diff --git a/README.md b/README.md index 3eadcbff47371..f53d787a9a3d1 100644 --- a/README.md +++ b/README.md @@ -211,3 +211,9 @@ We have [stickers](http://shop.planetargon.com/products/ohmyzsh-stickers-set-of- ## License Oh My Zsh is released under the [MIT license](LICENSE.txt). + +## About Planet Argon + +![Planet Argon](http://pa-github-assets.s3.amazonaws.com/PARGON_logo_digital_COL-small.jpg) + +Oh My Zsh was started by the team at [Planet Argon](https://www.planetargon.com/?utm_source=github), a [Ruby on Rails development agency](https://www.planetargon.com/skills/ruby-on-rails-development?utm_source=github). diff --git a/lib/functions.zsh b/lib/functions.zsh index f9d4a9717d7dd..9f11318d2c06c 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -3,11 +3,11 @@ function zsh_stats() { } function uninstall_oh_my_zsh() { - env ZSH=$ZSH /bin/sh $ZSH/tools/uninstall.sh + env ZSH=$ZSH sh $ZSH/tools/uninstall.sh } function upgrade_oh_my_zsh() { - env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh + env ZSH=$ZSH sh $ZSH/tools/upgrade.sh } function take() { diff --git a/lib/git.zsh b/lib/git.zsh index 1c76d58829bae..f7eccb81d933c 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -76,10 +76,21 @@ function git_current_branch() { # Gets the number of commits ahead from remote function git_commits_ahead() { - if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then - local COMMITS - COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ') - echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" + if command git rev-parse --git-dir &>/dev/null; then + local commits="$(git rev-list --count @{upstream}..HEAD)" + if [[ "$commits" != 0 ]]; then + echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" + fi + fi +} + +# Gets the number of commits behind remote +function git_commits_behind() { + if command git rev-parse --git-dir &>/dev/null; then + local commits="$(git rev-list --count HEAD..@{upstream})" + if [[ "$commits" != 0 ]]; then + echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX" + fi fi } @@ -154,13 +165,13 @@ function git_prompt_status() { if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" fi - if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then + if $(echo "$INDEX" | grep '^## [^ ]\+ .*ahead' &> /dev/null); then STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS" fi - if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then + if $(echo "$INDEX" | grep '^## [^ ]\+ .*behind' &> /dev/null); then STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS" fi - if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then + if $(echo "$INDEX" | grep '^## [^ ]\+ .*diverged' &> /dev/null); then STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS" fi echo $STATUS diff --git a/lib/nvm.zsh b/lib/nvm.zsh index 61d997fc07806..4a8b6811e9c64 100644 --- a/lib/nvm.zsh +++ b/lib/nvm.zsh @@ -1,6 +1,6 @@ # get the node.js version function nvm_prompt_info() { - [ -f "$HOME/.nvm/nvm.sh" ] || return + [[ -f "$NVM_DIR/nvm.sh" ]] || return local nvm_prompt nvm_prompt=$(node -v 2>/dev/null) [[ "${nvm_prompt}x" == "x" ]] && return diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh index 6cc5ac63023c9..ed258f0ea6947 100644 --- a/oh-my-zsh.sh +++ b/oh-my-zsh.sh @@ -22,7 +22,7 @@ fi # Set ZSH_CACHE_DIR to the path where cache files should be created # or else we will use the default cache/ if [[ -z "$ZSH_CACHE_DIR" ]]; then - ZSH_CACHE_DIR="$ZSH/cache/" + ZSH_CACHE_DIR="$ZSH/cache" fi diff --git a/plugins/archlinux/README.md b/plugins/archlinux/README.md index ad42d4cd282bf..785538a564e9a 100644 --- a/plugins/archlinux/README.md +++ b/plugins/archlinux/README.md @@ -1,64 +1,69 @@ -## ARCHLINUX PLUGIN +# Archlinux plugin +## Features ---- +#### YAOURT + +| Alias | Command | Description | +|---------|------------------------------------|---------------------------------------------------------------------| +| yaconf | yaourt -C | Fix all configuration files with vimdiff | +| yain | yaourt -S | Install packages from the repositories | +| yains | yaourt -U | Install a package from a local file | +| yainsd | yaourt -S --asdeps | Install packages as dependencies of another package | +| yaloc | yaourt -Qi | Display information about a package in the local database | +| yalocs | yaourt -Qs | Search for packages in the local database | +| yalst | yaourt -Qe | List installed packages including from AUR (tagged as "local") | +| yamir | yaourt -Syy | Force refresh of all package lists after updating mirrorlist | +| yaorph | yaourt -Qtd | Remove orphans using yaourt | +| yare | yaourt -R | Remove packages, keeping its settings and dependencies | +| yarem | yaourt -Rns | Remove packages, including its settings and unneeded dependencies | +| yarep | yaourt -Si | Display information about a package in the repositories | +| yareps | yaourt -Ss | Search for packages in the repositories | +| yaupd | yaourt -Sy && sudo abs && sudo aur | Update and refresh local package, ABS and AUR databases | +| yaupd | yaourt -Sy && sudo abs | Update and refresh the local package and ABS databases | +| yaupd | yaourt -Sy && sudo aur | Update and refresh the local package and AUR databases | +| yaupd | yaourt -Sy | Update and refresh the local package database | +| yaupg | yaourt -Syua | Sync with repositories before upgrading all packages (from AUR too) | +| yasu | yaourt -Syua --no-confirm | Same as `yaupg`, but without confirmation | +| upgrade | yaourt -Syu | Sync with repositories before upgrading packages | -### FEATURES +#### PACMAN -| Alias | Function | Description | -|:------------:|-----------------------------------------|:--------------------------------------------------------------------------------------------------------------------| -| pacin | sudo pacman -S | Install specific package(s) from the repositories | -| pacins | sudo pacman -U | Install specific package not from the repositories but from a file | -| pacinsd | sudo pacman -S --asdeps | Install given package(s) as dependencies of another package | -| pacloc | pacman -Qi | Display information about a given package in the local database | -| paclocs | pacman -Qs | Search for package(s) in the local database | -| paclsorphans | sudo pacman -Qdt' | List all orphaned packages | -| pacmir | sudo pacman -Syy | Force refresh of all package lists after updating /etc/pacman.d/mirrorlist | -| pacre | sudo pacman -R | Remove the specified package(s), retaining its configuration(s) and required dependencies | -| pacrem | sudo pacman -Rns | Remove the specified package(s), its configuration(s) and unneeded dependencies | -| pacrep | pacman -Si | Display information about a given package in the repositories | -| pacreps | pacman -Ss | Search for package(s) in the repositories | -| pacrmorphans | sudo pacman -Rs $(pacman -Qtdq)' | Delete all orphaned packages | -| pacupd | sudo pacman -Sy && sudo abs && sudo aur | Update and refresh the local package, ABS and AUR databases against repositories | -| pacupd | sudo pacman -Sy && sudo abs | Update and refresh the local package and ABS databases against repositories | -| pacupd | sudo pacman -Sy && sudo aur | Update and refresh the local package and AUR databases against repositories | -| pacupd | sudo pacman -Sy | Update and refresh the local package database against repositories | -| pacupg | sudo pacman -Syu | Synchronize with repositories before upgrading packages that are out of date on the local system. | -| yaconf | yaourt -C | Fix all configuration files with vimdiff | -| yain | yaourt -S | Install specific package(s) from the repositories | -| yains | yaourt -U | Install specific package not from the repositories but from a file | -| yainsd | yaourt -S --asdeps | Install given package(s) as dependencies of another package | -| yaloc | yaourt -Qi | Display information about a given package in the local database | -| yalocs | yaourt -Qs | Search for package(s) in the local database | -| yalst | yaourt -Qe | List installed packages, even those installed from AUR (they're tagged as "local") | -| yamir | yaourt -Syy | Force refresh of all package lists after updating /etc/pacman.d/mirrorlist | -| yaorph | yaourt -Qtd | Remove orphans using yaourt | -| yare | yaourt -R | Remove the specified package(s), retaining its configuration(s) and required dependencies | -| yarem | yaourt -Rns | Remove the specified package(s), its configuration(s) and unneeded dependencies | -| yarep | yaourt -Si | Display information about a given package in the repositories | -| yareps | yaourt -Ss | Search for package(s) in the repositories | -| yasu | yaourt --sucre | Same as yaupg, but without confirmation | -| yaupd | yaourt -Sy && sudo abs && sudo aur | Update and refresh the local package, ABS and AUR databases against repositories | -| yaupd | yaourt -Sy && sudo abs | Update and refresh the local package and ABS databases against repositories | -| yaupd | yaourt -Sy && sudo aur | Update and refresh the local package and AUR databases against repositories | -| yaupd | yaourt -Sy | Update and refresh the local package database against repositories | -| yaupg | yaourt -Syua | Synchronize with repositories before upgrading packages (AUR packages too) that are out of date on the local system | +| Alias | Command | Description | +|--------------|-----------------------------------------|--------------------------------------------------------------| +| pacin | sudo pacman -S | Install packages from the repositories | +| pacins | sudo pacman -U | Install a package from a local file | +| pacinsd | sudo pacman -S --asdeps | Install packages as dependencies of another package | +| pacloc | pacman -Qi | Display information about a package in the local database | +| paclocs | pacman -Qs | Search for packages in the local database | +| paclsorphans | sudo pacman -Qdt | List all orphaned packages | +| pacmir | sudo pacman -Syy | Force refresh of all package lists after updating mirrorlist | +| pacre | sudo pacman -R | Remove packages, keeping its settings and dependencies | +| pacrem | sudo pacman -Rns | Remove packages, including its settings and dependencies | +| pacrep | pacman -Si | Display information about a package in the repositories | +| pacreps | pacman -Ss | Search for packages in the repositories | +| pacrmorphans | sudo pacman -Rs $(pacman -Qtdq) | Delete all orphaned packages | +| pacupd | sudo pacman -Sy && sudo abs && sudo aur | Update and refresh the local package, ABS and AUR databases | +| pacupd | sudo pacman -Sy && sudo abs | Update and refresh the local package and ABS databases | +| pacupd | sudo pacman -Sy && sudo aur | Update and refresh the local package and AUR databases | +| pacupd | sudo pacman -Sy | Update and refresh the local package database | +| pacupg | sudo pacman -Syu | Sync with repositories before upgrading packages | +| upgrade | sudo pacman -Syu | Sync with repositories before upgrading packages | -| Function | Description | -|----------------|:------------------------------------------------------------------------------------------------------------------| -| pacdisowned | List all disowned files in your system | -| paclist | List all installed packages with a short description - [Source](https://bbs.archlinux.org/viewtopic.php?id=93683) | -| pacmanallkeys | Get all keys for developers and trusted users | -| pacmansignkeys | | +| Function | Description | +|----------------|------------------------------------------------------| +| pacdisowned | List all disowned files in your system | +| paclist | List all installed packages with a short description | +| pacmanallkeys | Get all keys for developers and trusted users | +| pacmansignkeys | Locally trust all keys passed as parameters | --- -### CONTRIBUTORS - - Benjamin Boudreau - dreurmail@gmail.com - - Celso Miranda - contacto@celsomiranda.net - - KhasMek - Boushh@gmail.com - - Martin Putniorz - mputniorz@gmail.com - - MatthR3D - matthr3d@gmail.com - - ornicar - thibault.duplessis@gmail.com +## Contributors ---- +- Benjamin Boudreau - dreurmail@gmail.com +- Celso Miranda - contacto@celsomiranda.net +- KhasMek - Boushh@gmail.com +- Martin Putniorz - mputniorz@gmail.com +- MatthR3D - matthr3d@gmail.com +- ornicar - thibault.duplessis@gmail.com diff --git a/plugins/archlinux/archlinux.plugin.zsh b/plugins/archlinux/archlinux.plugin.zsh index 99de5b936b119..1637e8561d9a8 100644 --- a/plugins/archlinux/archlinux.plugin.zsh +++ b/plugins/archlinux/archlinux.plugin.zsh @@ -1,75 +1,75 @@ -# Archlinux zsh aliases and functions -# Usage is also described at https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins - -# Look for yaourt, and add some useful functions if we have it. -if (( $+commands[yaourt] )); then +if ! (( $+commands[yaourt] )); then + upgrade() { + sudo pacman -Syu + } +else upgrade () { yaourt -Syu } - alias yaconf='yaourt -C' # Fix all configuration files with vimdiff - # Pacman - https://wiki.archlinux.org/index.php/Pacman_Tips - alias yaupg='yaourt -Syua' # Synchronize with repositories before upgrading packages (AUR packages too) that are out of date on the local system. - alias yasu='yaourt --sucre' # Same as yaupg, but without confirmation - alias yain='yaourt -S' # Install specific package(s) from the repositories - alias yains='yaourt -U' # Install specific package not from the repositories but from a file - alias yare='yaourt -R' # Remove the specified package(s), retaining its configuration(s) and required dependencies - alias yarem='yaourt -Rns' # Remove the specified package(s), its configuration(s) and unneeded dependencies - alias yarep='yaourt -Si' # Display information about a given package in the repositories - alias yareps='yaourt -Ss' # Search for package(s) in the repositories - alias yaloc='yaourt -Qi' # Display information about a given package in the local database - alias yalocs='yaourt -Qs' # Search for package(s) in the local database - alias yalst='yaourt -Qe' # List installed packages, even those installed from AUR (they're tagged as "local") - alias yaorph='yaourt -Qtd' # Remove orphans using yaourt - # Additional yaourt alias examples + + alias yaconf='yaourt -C' + alias yaupg='yaourt -Syua' + alias yasu='yaourt -Syua --noconfirm' + alias yain='yaourt -S' + alias yains='yaourt -U' + alias yare='yaourt -R' + alias yarem='yaourt -Rns' + alias yarep='yaourt -Si' + alias yareps='yaourt -Ss' + alias yaloc='yaourt -Qi' + alias yalocs='yaourt -Qs' + alias yalst='yaourt -Qe' + alias yaorph='yaourt -Qtd' + alias yainsd='yaourt -S --asdeps' + alias yamir='yaourt -Syy' + + if (( $+commands[abs] && $+commands[aur] )); then - alias yaupd='yaourt -Sy && sudo abs && sudo aur' # Update and refresh the local package, ABS and AUR databases against repositories + alias yaupd='yaourt -Sy && sudo abs && sudo aur' elif (( $+commands[abs] )); then - alias yaupd='yaourt -Sy && sudo abs' # Update and refresh the local package and ABS databases against repositories + alias yaupd='yaourt -Sy && sudo abs' elif (( $+commands[aur] )); then - alias yaupd='yaourt -Sy && sudo aur' # Update and refresh the local package and AUR databases against repositories + alias yaupd='yaourt -Sy && sudo aur' else - alias yaupd='yaourt -Sy' # Update and refresh the local package database against repositories + alias yaupd='yaourt -Sy' fi - alias yainsd='yaourt -S --asdeps' # Install given package(s) as dependencies of another package - alias yamir='yaourt -Syy' # Force refresh of all package lists after updating /etc/pacman.d/mirrorlist -else - upgrade() { - sudo pacman -Syu - } fi # Pacman - https://wiki.archlinux.org/index.php/Pacman_Tips -alias pacupg='sudo pacman -Syu' # Synchronize with repositories before upgrading packages that are out of date on the local system. -alias pacin='sudo pacman -S' # Install specific package(s) from the repositories -alias pacins='sudo pacman -U' # Install specific package not from the repositories but from a file -alias pacre='sudo pacman -R' # Remove the specified package(s), retaining its configuration(s) and required dependencies -alias pacrem='sudo pacman -Rns' # Remove the specified package(s), its configuration(s) and unneeded dependencies -alias pacrep='pacman -Si' # Display information about a given package in the repositories -alias pacreps='pacman -Ss' # Search for package(s) in the repositories -alias pacloc='pacman -Qi' # Display information about a given package in the local database -alias paclocs='pacman -Qs' # Search for package(s) in the local database -# Additional pacman alias examples +alias pacupg='sudo pacman -Syu' +alias pacin='sudo pacman -S' +alias pacins='sudo pacman -U' +alias pacre='sudo pacman -R' +alias pacrem='sudo pacman -Rns' +alias pacrep='pacman -Si' +alias pacreps='pacman -Ss' +alias pacloc='pacman -Qi' +alias paclocs='pacman -Qs' +alias pacinsd='sudo pacman -S --asdeps' +alias pacmir='sudo pacman -Syy' +alias paclsorphans='sudo pacman -Qdt' +alias pacrmorphans='sudo pacman -Rs $(pacman -Qtdq)' + + if (( $+commands[abs] && $+commands[aur] )); then - alias pacupd='sudo pacman -Sy && sudo abs && sudo aur' # Update and refresh the local package, ABS and AUR databases against repositories + alias pacupd='sudo pacman -Sy && sudo abs && sudo aur' elif (( $+commands[abs] )); then - alias pacupd='sudo pacman -Sy && sudo abs' # Update and refresh the local package and ABS databases against repositories + alias pacupd='sudo pacman -Sy && sudo abs' elif (( $+commands[aur] )); then - alias pacupd='sudo pacman -Sy && sudo aur' # Update and refresh the local package and AUR databases against repositories + alias pacupd='sudo pacman -Sy && sudo aur' else - alias pacupd='sudo pacman -Sy' # Update and refresh the local package database against repositories + alias pacupd='sudo pacman -Sy' fi -alias pacinsd='sudo pacman -S --asdeps' # Install given package(s) as dependencies of another package -alias pacmir='sudo pacman -Syy' # Force refresh of all package lists after updating /etc/pacman.d/mirrorlist -# https://bbs.archlinux.org/viewtopic.php?id=93683 paclist() { - LC_ALL=C pacman -Qei $(pacman -Qu|cut -d" " -f 1)|awk ' BEGIN {FS=":"}/^Name/{printf("\033[1;36m%s\033[1;37m", $2)}/^Description/{print $2}' + # Source: https://bbs.archlinux.org/viewtopic.php?id=93683 + LC_ALL=C pacman -Qei $(pacman -Qu | cut -d " " -f 1) | \ + awk 'BEGIN {FS=":"} /^Name/{printf("\033[1;36m%s\033[1;37m", $2)} /^Description/{print $2}' } -alias paclsorphans='sudo pacman -Qdt' -alias pacrmorphans='sudo pacman -Rs $(pacman -Qtdq)' - pacdisowned() { + emulate -L zsh + tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$ db=$tmp/db fs=$tmp/fs @@ -79,21 +79,21 @@ pacdisowned() { pacman -Qlq | sort -u > "$db" - find /bin /etc /lib /sbin /usr \ - ! -name lost+found \ - \( -type d -printf '%p/\n' -o -print \) | sort > "$fs" + find /bin /etc /lib /sbin /usr ! -name lost+found \ + \( -type d -printf '%p/\n' -o -print \) | sort > "$fs" comm -23 "$fs" "$db" } pacmanallkeys() { - # Get all keys for developers and trusted users - curl https://www.archlinux.org/{developers,trustedusers}/ | - awk -F\" '(/pgp.mit.edu/) {sub(/.*search=0x/,"");print $1}' | - xargs sudo pacman-key --recv-keys + emulate -L zsh + curl -s https://www.archlinux.org/people/{developers,trustedusers}/ | \ + awk -F\" '(/pgp.mit.edu/) { sub(/.*search=0x/,""); print $1}' | \ + xargs sudo pacman-key --recv-keys } pacmansignkeys() { + emulate -L zsh for key in $*; do sudo pacman-key --recv-keys $key sudo pacman-key --lsign-key $key diff --git a/plugins/battery/battery.plugin.zsh b/plugins/battery/battery.plugin.zsh index 014bb15dd0ce0..0bb9e77f09174 100644 --- a/plugins/battery/battery.plugin.zsh +++ b/plugins/battery/battery.plugin.zsh @@ -67,12 +67,12 @@ if [[ "$OSTYPE" = darwin* ]] ; then elif [[ $(uname) == "Linux" ]] ; then function battery_is_charging() { - ! [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] + ! [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] } function battery_pct() { if (( $+commands[acpi] )) ; then - echo "$(acpi | cut -f2 -d ',' | tr -cd '[:digit:]')" + echo "$(acpi 2>/dev/null | cut -f2 -d ',' | tr -cd '[:digit:]')" fi } @@ -85,14 +85,14 @@ elif [[ $(uname) == "Linux" ]] ; then } function battery_time_remaining() { - if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then - echo $(acpi | cut -f3 -d ',') + if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then + echo $(acpi 2>/dev/null | cut -f3 -d ',') fi } function battery_pct_prompt() { b=$(battery_pct_remaining) - if [[ $(acpi 2&>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then + if [[ $(acpi 2>/dev/null | grep -c '^Battery.*Discharging') -gt 0 ]] ; then if [ $b -gt 50 ] ; then color='green' elif [ $b -gt 20 ] ; then diff --git a/plugins/brew-cask/brew-cask.plugin.zsh b/plugins/brew-cask/brew-cask.plugin.zsh deleted file mode 100644 index 91ce0f49816ca..0000000000000 --- a/plugins/brew-cask/brew-cask.plugin.zsh +++ /dev/null @@ -1,84 +0,0 @@ -# Autocompletion for homebrew-cask. -# -# This script intercepts calls to the brew plugin and adds autocompletion -# for the cask subcommand. -# -# Author: https://github.com/pstadler - -compdef _brew-cask brew - -_brew-cask() -{ - local curcontext="$curcontext" state line - typeset -A opt_args - - _arguments -C \ - ':command:->command' \ - ':subcmd:->subcmd' \ - '*::options:->options' - - case $state in - (command) - __call_original_brew - cask_commands=( - 'cask:manage casks' - ) - _describe -t commands 'brew cask command' cask_commands ;; - - (subcmd) - case "$line[1]" in - cask) - if (( CURRENT == 3 )); then - local -a subcommands - subcommands=( - "alfred:used to modify Alfred's scope to include the Caskroom" - 'audit:verifies installability of casks' - 'checklinks:checks for bad cask links' - 'cleanup:cleans up cached downloads' - 'create:creates a cask of the given name and opens it in an editor' - 'doctor:checks for configuration issues' - 'edit:edits the cask of the given name' - 'fetch:downloads Cask resources to local cache' - 'home:opens the homepage of the cask of the given name' - 'info:displays information about the cask of the given name' - 'install:installs the cask of the given name' - 'list:with no args, lists installed casks; given installed casks, lists installed files' - 'search:searches all known casks' - 'uninstall:uninstalls the cask of the given name' - "update:a synonym for 'brew update'" - ) - _describe -t commands "brew cask subcommand" subcommands - fi ;; - - *) - __call_original_brew ;; - esac ;; - - (options) - local -a casks installed_casks - local expl - case "$line[2]" in - list|uninstall) - __brew_installed_casks - _wanted installed_casks expl 'installed casks' compadd -a installed_casks ;; - audit|edit|home|info|install) - __brew_all_casks - _wanted casks expl 'all casks' compadd -a casks ;; - esac ;; - esac -} - -__brew_all_casks() { - casks=(`brew cask search`) -} - -__brew_installed_casks() { - installed_casks=(`brew cask list`) -} - -__call_original_brew() -{ - local ret=1 - _call_function ret _brew - compdef _brew-cask brew -} diff --git a/plugins/brew/_brew b/plugins/brew/_brew deleted file mode 100644 index 1f24bd67b1057..0000000000000 --- a/plugins/brew/_brew +++ /dev/null @@ -1,145 +0,0 @@ -#compdef brew -#autoload - -# imported from https://github.com/Homebrew/homebrew/blob/29f73d2212c2b202fe25f69dcbf440d8391fa4c9/Library/Contributions/brew_zsh_completion.zsh - -# Brew ZSH completion function -# Drop this somewhere in your $fpath (like /usr/share/zsh/site-functions) -# and rename it _brew -# -# altered from _fink - -_brew_all_formulae() { - formulae=(`brew search`) -} - -_brew_installed_formulae() { - installed_formulae=(`brew list`) -} - -_brew_installed_taps() { - installed_taps=(`brew tap`) -} - -_brew_official_taps() { - official_taps=(`brew tap --list-official`) -} - -_brew_pinned_taps() { - pinned_taps=(`brew tap --list-pinned`) -} - -_brew_outdated_formulae() { - outdated_formulae=(`brew outdated`) -} - -local -a _1st_arguments -_1st_arguments=( - 'audit:check formulae for Homebrew coding style' - 'cat:display formula file for a formula' - 'cleanup:uninstall unused and old versions of packages' - 'commands:show a list of commands' - 'config:show homebrew and system configuration' - 'create:create a new formula' - 'deps:list dependencies and dependants of a formula' - 'desc:display a description of a formula' - 'doctor:audits your installation for common issues' - 'edit:edit a formula' - 'fetch:download formula resources to the cache' - 'gist-logs:generate a gist of the full build logs' - 'home:visit the homepage of a formula or the brew project' - 'info:information about a formula' - 'install:install a formula' - 'reinstall:install a formula anew; re-using its current options' - 'leaves:show installed formulae that are not dependencies of another installed formula' - 'link:link a formula' - 'linkapps:symlink .app bundles provided by formulae into /Applications' - 'list:list files in a formula or not-installed formulae' - 'log:git commit log for a formula' - 'missing:check all installed formuale for missing dependencies.' - 'migrate:migrate renamed formula to new name' - 'outdated:list formulae for which a newer version is available' - 'pin:pin specified formulae' - 'postinstall:perform post_install for a given formula' - 'prune:remove dead links' - 'remove:remove a formula' - 'search:search for a formula (/regex/ or string)' - 'switch:switch between different versions of a formula' - 'tap:tap a new formula repository from GitHub, or list existing taps' - 'tap-info:information about a tap' - 'tap-pin:pin a tap' - 'tap-unpin:unpin a tap' - 'test-bot:test a formula and build a bottle' - 'uninstall:uninstall a formula' - 'unlink:unlink a formula' - 'unlinkapps:remove symlinked .app bundles provided by formulae from /Applications' - 'unpin:unpin specified formulae' - 'untap:remove a tapped repository' - 'update:fetch latest version of Homebrew and all formulae' - 'upgrade:upgrade outdated formulae' - 'uses:show formulae which depend on a formula' - `brew commands --quiet --include-aliases` -) - -local expl -local -a formulae installed_formulae installed_taps official_taps outdated_formulae - -_arguments \ - '(-v)-v[verbose]' \ - '(--cellar)--cellar[brew cellar]' \ - '(--env)--env[brew environment]' \ - '(--repository)--repository[brew repository]' \ - '(--version)--version[version information]' \ - '(--prefix)--prefix[where brew lives on this system]' \ - '(--cache)--cache[brew cache]' \ - '*:: :->subcmds' && return 0 - -if (( CURRENT == 1 )); then - _describe -t commands "brew subcommand" _1st_arguments - return -fi - -case "$words[1]" in - install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|desc|edit|options|switch) - _brew_all_formulae - _wanted formulae expl 'all formulae' compadd -a formulae ;; - linkapps|unlinkapps) - _arguments \ - '(--local)--local[operate on ~/Applications instead of /Applications]' \ - '1: :->forms' && return 0 - - if [[ "$state" == forms ]]; then - _brew_installed_formulae - _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae - fi ;; - list|ls) - _arguments \ - '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \ - '(--pinned)--pinned[list all versions of pinned formulae]' \ - '(--versions)--versions[list all installed versions of a formula]' \ - '1: :->forms' && return 0 - - if [[ "$state" == forms ]]; then - _brew_installed_formulae - _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae - fi ;; - remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin) - _brew_installed_formulae - _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;; - search|-S) - _arguments \ - '(--macports)--macports[search the macports repository]' \ - '(--fink)--fink[search the fink repository]' ;; - untap|tap-info|tap-pin) - _brew_installed_taps - _wanted installed_taps expl 'installed taps' compadd -a installed_taps ;; - tap) - _brew_official_taps - _wanted official_taps expl 'official taps' compadd -a official_taps ;; - tap-unpin) - _brew_pinned_taps - _wanted pinned_taps expl 'pinned taps' compadd -a pinned_taps ;; - upgrade) - _brew_outdated_formulae - _wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;; -esac diff --git a/plugins/bundler/bundler.plugin.zsh b/plugins/bundler/bundler.plugin.zsh index 382a1a471cca4..c5284dbb19d68 100644 --- a/plugins/bundler/bundler.plugin.zsh +++ b/plugins/bundler/bundler.plugin.zsh @@ -58,7 +58,7 @@ bundle_install() { if [[ $bundler_version > '1.4.0' || $bundler_version = '1.4.0' ]]; then if [[ "$OSTYPE" = darwin* ]] then - local cores_num="$(sysctl hw.ncpu | awk '{print $2}')" + local cores_num="$(sysctl -n hw.ncpu)" else local cores_num="$(nproc)" fi diff --git a/plugins/cask/README.md b/plugins/cask/README.md new file mode 100644 index 0000000000000..6457fd858186d --- /dev/null +++ b/plugins/cask/README.md @@ -0,0 +1,11 @@ +# cask plugin + +Loads `cask` completion from non-standard locations, such as if installed +via Homebrew or others. To enable it, add `cask` to your plugins array: + +```zsh +plugins=(... cask) +``` + +Make sure you have the `cask` directory in your `$PATH` before loading +Oh My Zsh, otherwise you'll get the "command not found" error. diff --git a/plugins/cask/cask.plugin.zsh b/plugins/cask/cask.plugin.zsh index c558629243d22..29120b3062ddf 100644 --- a/plugins/cask/cask.plugin.zsh +++ b/plugins/cask/cask.plugin.zsh @@ -1,5 +1,26 @@ -if which cask &> /dev/null; then - source $(dirname $(which cask))/../etc/cask_completion.zsh -else - print "zsh cask plugin: cask not found" -fi +() { + emulate -L zsh + + if ! (( $+commands[cask] )); then + print "zsh cask plugin: cask command not found" >&2 + return + fi + + cask_base=${commands[cask]:h:h} + + # Plain cask installation location (for Cask 0.7.2 and earlier) + comp_files=($cask_base/etc/cask_completion.zsh) + + # Mac Homebrew installs the completion in a different location + if (( $+commands[brew] )); then + comp_files+=($(brew --prefix)/share/zsh/site-functions/cask_completion.zsh) + fi + + # Load first found file + for f in $comp_files; do + if [[ -f "$f" ]]; then + source "$f" + break + fi + done +} diff --git a/plugins/coffee/README.md b/plugins/coffee/README.md index 432ce341422d8..d6cd074d3d74d 100644 --- a/plugins/coffee/README.md +++ b/plugins/coffee/README.md @@ -1,7 +1,7 @@ ## Coffeescript Plugin This plugin provides aliases for quickly compiling and previewing your -cofeescript code. +coffeescript code. When writing Coffeescript it's very common to want to preview the output of a certain snippet of code, either because you want to test the output or because diff --git a/plugins/dircycle/dircycle.plugin.zsh b/plugins/dircycle/dircycle.plugin.zsh index 8a406b54d772a..2f32277cf03dc 100644 --- a/plugins/dircycle/dircycle.plugin.zsh +++ b/plugins/dircycle/dircycle.plugin.zsh @@ -8,11 +8,21 @@ # pushd +N: start counting from left of `dirs' output # pushd -N: start counting from right of `dirs' output +switch-to-dir () { + while ! builtin pushd -q $1 &>/dev/null; do + # We found a missing directory: pop it out of the dir stack + builtin popd -q $1 + + # Stop trying if there are no more directories in the dir stack + [[ ${#dirstack} -eq 0 ]] && break + done +} + insert-cycledleft () { emulate -L zsh setopt nopushdminus - builtin pushd -q +1 &>/dev/null || true + switch-to-dir +1 zle reset-prompt } zle -N insert-cycledleft @@ -21,7 +31,7 @@ insert-cycledright () { emulate -L zsh setopt nopushdminus - builtin pushd -q -0 &>/dev/null || true + switch-to-dir -0 zle reset-prompt } zle -N insert-cycledright diff --git a/plugins/docker-compose/README.md b/plugins/docker-compose/README.md index 567b821487af8..d3fcb29fef46c 100644 --- a/plugins/docker-compose/README.md +++ b/plugins/docker-compose/README.md @@ -1,5 +1,4 @@ # Docker-compose plugin for oh my zsh -A copy of the completion script from the [docker-compose](1) git repo. +A copy of the completion script from the [docker-compose](https://github.com/docker/compose/blob/master/contrib/completion/zsh/_docker-compose) git repo. -[1]:[https://github.com/docker/compose/blob/master/contrib/completion/zsh/_docker-compose] diff --git a/plugins/docker-compose/_docker-compose b/plugins/docker-compose/_docker-compose index 19c06675ad505..2947cef382438 100644 --- a/plugins/docker-compose/_docker-compose +++ b/plugins/docker-compose/_docker-compose @@ -7,7 +7,7 @@ # ------------------------------------------------------------------------- # Version # ------- -# 0.1.0 +# 1.5.0 # ------------------------------------------------------------------------- # Authors # ------- @@ -19,58 +19,69 @@ # * @felixr docker zsh completion script : https://github.com/felixr/docker-zsh-completion # ------------------------------------------------------------------------- -# For compatibility reasons, Compose and therefore its completion supports several -# stack compositon files as listed here, in descending priority. -# Support for these filenames might be dropped in some future version. -__docker-compose_compose_file() { - local file - for file in docker-compose.y{,a}ml fig.y{,a}ml ; do - [ -e $file ] && { - echo $file - return - } - done - echo docker-compose.yml +__docker-compose_q() { + docker-compose 2>/dev/null $compose_options "$@" } -# Extracts all service names from docker-compose.yml. -___docker-compose_all_services_in_compose_file() { +# All services defined in docker-compose.yml +__docker-compose_all_services_in_compose_file() { local already_selected local -a services - already_selected=$(echo ${words[@]} | tr " " "|") - awk -F: '/^[a-zA-Z0-9]/{print $1}' "${compose_file:-$(__docker-compose_compose_file)}" 2>/dev/null | grep -Ev "$already_selected" + already_selected=$(echo $words | tr " " "|") + __docker-compose_q config --services \ + | grep -Ev "^(${already_selected})$" } # All services, even those without an existing container __docker-compose_services_all() { - services=$(___docker-compose_all_services_in_compose_file) - _alternative "args:services:($services)" + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + services=$(__docker-compose_all_services_in_compose_file) + _alternative "args:services:($services)" && ret=0 + + return ret } # All services that have an entry with the given key in their docker-compose.yml section -___docker-compose_services_with_key() { +__docker-compose_services_with_key() { local already_selected local -a buildable - already_selected=$(echo ${words[@]} | tr " " "|") + already_selected=$(echo $words | tr " " "|") # flatten sections to one line, then filter lines containing the key and return section name. - awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' "${compose_file:-$(__docker-compose_compose_file)}" 2>/dev/null | awk -F: -v key=": +$1:" '$0 ~ key {print $1}' 2>/dev/null | grep -Ev "$already_selected" + __docker-compose_q config \ + | sed -n -e '/^services:/,/^[^ ]/p' \ + | sed -n 's/^ //p' \ + | awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' \ + | grep " \+$1:" \ + | cut -d: -f1 \ + | grep -Ev "^(${already_selected})$" } # All services that are defined by a Dockerfile reference __docker-compose_services_from_build() { - buildable=$(___docker-compose_services_with_key build) - _alternative "args:buildable services:($buildable)" + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + buildable=$(__docker-compose_services_with_key build) + _alternative "args:buildable services:($buildable)" && ret=0 + + return ret } # All services that are defined by an image __docker-compose_services_from_image() { - pullable=$(___docker-compose_services_with_key image) - _alternative "args:pullable services:($pullable)" + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + pullable=$(__docker-compose_services_with_key image) + _alternative "args:pullable services:($pullable)" && ret=0 + + return ret } __docker-compose_get_services() { - local kind expl - declare -a running stopped lines args services + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local kind + declare -a running paused stopped lines args services docker_status=$(docker ps > /dev/null 2>&1) if [ $? -ne 0 ]; then @@ -80,64 +91,78 @@ __docker-compose_get_services() { kind=$1 shift - [[ $kind = (stopped|all) ]] && args=($args -a) + [[ $kind =~ (stopped|all) ]] && args=($args -a) - lines=(${(f)"$(_call_program commands docker ps ${args})"}) - services=(${(f)"$(_call_program commands docker-compose 2>/dev/null ${compose_file:+-f $compose_file} ${compose_project:+-p $compose_project} ps -q)"}) + lines=(${(f)"$(_call_program commands docker $docker_options ps $args)"}) + services=(${(f)"$(_call_program commands docker-compose 2>/dev/null $compose_options ps -q)"}) # Parse header line to find columns local i=1 j=1 k header=${lines[1]} declare -A begin end - while (( $j < ${#header} - 1 )) { - i=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 1)) - j=$(( $i + ${${header[$i,-1]}[(i) ]} - 1)) - k=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 2)) - begin[${header[$i,$(($j-1))]}]=$i - end[${header[$i,$(($j-1))]}]=$k - } + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done lines=(${lines[2,-1]}) # Container ID local line s name local -a names for line in $lines; do - if [[ $services == *"${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}"* ]]; then + if [[ ${services[@]} == *"${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}"* ]]; then names=(${(ps:,:)${${line[${begin[NAMES]},-1]}%% *}}) for name in $names; do s="${${name%_*}#*_}:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" s="$s, ${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}" - s="$s, ${${${line[$begin[IMAGE],$end[IMAGE]]}/:/\\:}%% ##}" + s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then stopped=($stopped $s) else + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = *\(Paused\)* ]]; then + paused=($paused $s) + fi running=($running $s) fi done fi done - [[ $kind = (running|all) ]] && _describe -t services-running "running services" running - [[ $kind = (stopped|all) ]] && _describe -t services-stopped "stopped services" stopped + [[ $kind =~ (running|all) ]] && _describe -t services-running "running services" running "$@" && ret=0 + [[ $kind =~ (paused|all) ]] && _describe -t services-paused "paused services" paused "$@" && ret=0 + [[ $kind =~ (stopped|all) ]] && _describe -t services-stopped "stopped services" stopped "$@" && ret=0 + + return ret +} + +__docker-compose_pausedservices() { + [[ $PREFIX = -* ]] && return 1 + __docker-compose_get_services paused "$@" } __docker-compose_stoppedservices() { + [[ $PREFIX = -* ]] && return 1 __docker-compose_get_services stopped "$@" } __docker-compose_runningservices() { + [[ $PREFIX = -* ]] && return 1 __docker-compose_get_services running "$@" } -__docker-compose_services () { +__docker-compose_services() { + [[ $PREFIX = -* ]] && return 1 __docker-compose_get_services all "$@" } __docker-compose_caching_policy() { - oldp=( "$1"(Nmh+1) ) # 1 hour + oldp=( "$1"(Nmh+1) ) # 1 hour (( $#oldp )) } -__docker-compose_commands () { +__docker-compose_commands() { local cache_policy zstyle -s ":completion:${curcontext}:" cache-policy cache_policy @@ -151,110 +176,204 @@ __docker-compose_commands () { local -a lines lines=(${(f)"$(_call_program commands docker-compose 2>&1)"}) _docker_compose_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) - _store_cache docker_compose_subcommands _docker_compose_subcommands + (( $#_docker_compose_subcommands > 0 )) && _store_cache docker_compose_subcommands _docker_compose_subcommands fi _describe -t docker-compose-commands "docker-compose command" _docker_compose_subcommands } -__docker-compose_subcommand () { - local -a _command_args +__docker-compose_subcommand() { + local opts_help opts_force_recreate opts_no_recreate opts_no_build opts_remove_orphans opts_timeout opts_no_color opts_no_deps + + opts_help='(: -)--help[Print usage]' + opts_force_recreate="(--no-recreate)--force-recreate[Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.]" + opts_no_recreate="(--force-recreate)--no-recreate[If containers already exist, don't recreate them. Incompatible with --force-recreate.]" + opts_no_build="(--build)--no-build[Don't build an image, even if it's missing.]" + opts_remove_orphans="--remove-orphans[Remove containers for services not defined in the Compose file]" + opts_timeout=('(-t --timeout)'{-t,--timeout}"[Specify a shutdown timeout in seconds. (default: 10)]:seconds: ") + opts_no_color='--no-color[Produce monochrome output.]' + opts_no_deps="--no-deps[Don't start linked services.]" + integer ret=1 + case "$words[1]" in (build) _arguments \ - '--no-cache[Do not use cache when building the image]' \ + $opts_help \ + '--force-rm[Always remove intermediate containers.]' \ + '--no-cache[Do not use cache when building the image.]' \ + '--pull[Always attempt to pull a newer version of the image.]' \ '*:services:__docker-compose_services_from_build' && ret=0 ;; + (bundle) + _arguments \ + $opts_help \ + '(--output -o)'{--output,-o}'[Path to write the bundle file to. Defaults to ".dab".]:file:_files' && ret=0 + ;; + (config) + _arguments \ + $opts_help \ + '(--quiet -q)'{--quiet,-q}"[Only validate the configuration, don't print anything.]" \ + '--services[Print the service names, one per line.]' && ret=0 + ;; + (create) + _arguments \ + $opts_help \ + $opts_force_recreate \ + $opts_no_recreate \ + $opts_no_build \ + "(--no-build)--build[Build images before creating containers.]" \ + '*:services:__docker-compose_services_all' && ret=0 + ;; + (down) + _arguments \ + $opts_help \ + "--rmi[Remove images. Type must be one of: 'all': Remove all images used by any service. 'local': Remove only images that don't have a custom tag set by the \`image\` field.]:type:(all local)" \ + '(-v --volumes)'{-v,--volumes}"[Remove named volumes declared in the \`volumes\` section of the Compose file and anonymous volumes attached to containers.]" \ + $opts_remove_orphans && ret=0 + ;; + (events) + _arguments \ + $opts_help \ + '--json[Output events as a stream of json objects]' \ + '*:services:__docker-compose_services_all' && ret=0 + ;; + (exec) + _arguments \ + $opts_help \ + '-d[Detached mode: Run command in the background.]' \ + '--privileged[Give extended privileges to the process.]' \ + '--user=[Run the command as this user.]:username:_users' \ + '-T[Disable pseudo-tty allocation. By default `docker-compose exec` allocates a TTY.]' \ + '--index=[Index of the container if there are multiple instances of a service \[default: 1\]]:index: ' \ + '(-):running services:__docker-compose_runningservices' \ + '(-):command: _command_names -e' \ + '*::arguments: _normal' && ret=0 + ;; (help) _arguments ':subcommand:__docker-compose_commands' && ret=0 ;; (kill) _arguments \ + $opts_help \ '-s[SIGNAL to send to the container. Default signal is SIGKILL.]:signal:_signals' \ '*:running services:__docker-compose_runningservices' && ret=0 ;; (logs) _arguments \ - '--no-color[Produce monochrome output.]' \ + $opts_help \ + '(-f --follow)'{-f,--follow}'[Follow log output]' \ + $opts_no_color \ + '--tail=[Number of lines to show from the end of the logs for each container.]:number of lines: ' \ + '(-t --timestamps)'{-t,--timestamps}'[Show timestamps]' \ '*:services:__docker-compose_services_all' && ret=0 ;; - (migrate-to-labels) + (pause) _arguments \ - '(-):Recreate containers to add labels' && ret=0 + $opts_help \ + '*:running services:__docker-compose_runningservices' && ret=0 ;; (port) _arguments \ - '--protocol=-[tcp or udap (defaults to tcp)]:protocol:(tcp udp)' \ - '--index=-[index of the container if there are mutiple instances of a service (defaults to 1)]:index: ' \ + $opts_help \ + '--protocol=[tcp or udp \[default: tcp\]]:protocol:(tcp udp)' \ + '--index=[index of the container if there are multiple instances of a service \[default: 1\]]:index: ' \ '1:running services:__docker-compose_runningservices' \ '2:port:_ports' && ret=0 ;; (ps) _arguments \ + $opts_help \ '-q[Only display IDs]' \ '*:services:__docker-compose_services_all' && ret=0 ;; (pull) _arguments \ - '--allow-insecure-ssl[Allow insecure connections to the docker registry]' \ + $opts_help \ + '--ignore-pull-failures[Pull what it can and ignores images with pull failures.]' \ '*:services:__docker-compose_services_from_image' && ret=0 ;; + (push) + _arguments \ + $opts_help \ + '--ignore-push-failures[Push what it can and ignores images with push failures.]' \ + '*:services:__docker-compose_services' && ret=0 + ;; (rm) _arguments \ + $opts_help \ '(-f --force)'{-f,--force}"[Don't ask to confirm removal]" \ - '-v[Remove volumes associated with containers]' \ + '-v[Remove any anonymous volumes attached to containers]' \ '*:stopped services:__docker-compose_stoppedservices' && ret=0 ;; (run) _arguments \ - '--allow-insecure-ssl[Allow insecure connections to the docker registry]' \ + $opts_help \ '-d[Detached mode: Run container in the background, print new container name.]' \ - '--entrypoint[Overwrite the entrypoint of the image.]:entry point: ' \ '*-e[KEY=VAL Set an environment variable (can be used multiple times)]:environment variable KEY=VAL: ' \ - '(-u --user)'{-u,--user=-}'[Run as specified username or uid]:username or uid:_users' \ - "--no-deps[Don't start linked services.]" \ + '--entrypoint[Overwrite the entrypoint of the image.]:entry point: ' \ + '--name=[Assign a name to the container]:name: ' \ + $opts_no_deps \ + '(-p --publish)'{-p,--publish=}"[Publish a container's port(s) to the host]" \ '--rm[Remove container after run. Ignored in detached mode.]' \ "--service-ports[Run command with the service's ports enabled and mapped to the host.]" \ '-T[Disable pseudo-tty allocation. By default `docker-compose run` allocates a TTY.]' \ + '(-u --user)'{-u,--user=}'[Run as specified username or uid]:username or uid:_users' \ + '(-w --workdir)'{-w,--workdir=}'[Working directory inside the container]:workdir: ' \ '(-):services:__docker-compose_services' \ '(-):command: _command_names -e' \ '*::arguments: _normal' && ret=0 ;; (scale) - _arguments '*:running services:__docker-compose_runningservices' && ret=0 + _arguments \ + $opts_help \ + $opts_timeout \ + '*:running services:__docker-compose_runningservices' && ret=0 ;; (start) - _arguments '*:stopped services:__docker-compose_stoppedservices' && ret=0 + _arguments \ + $opts_help \ + '*:stopped services:__docker-compose_stoppedservices' && ret=0 ;; (stop|restart) _arguments \ - '(-t --timeout)'{-t,--timeout}"[Specify a shutdown timeout in seconds. (default: 10)]:seconds: " \ + $opts_help \ + $opts_timeout \ '*:running services:__docker-compose_runningservices' && ret=0 ;; + (unpause) + _arguments \ + $opts_help \ + '*:paused services:__docker-compose_pausedservices' && ret=0 + ;; (up) _arguments \ - '--allow-insecure-ssl[Allow insecure connections to the docker registry]' \ - '-d[Detached mode: Run containers in the background, print new container names.]' \ - '--no-color[Produce monochrome output.]' \ - "--no-deps[Don't start linked services.]" \ - "--no-recreate[If containers already exist, don't recreate them.]" \ - "--no-build[Don't build an image, even if it's missing]" \ - '(-t --timeout)'{-t,--timeout}"[Specify a shutdown timeout in seconds. (default: 10)]:seconds: " \ - "--x-smart-recreate[Only recreate containers whose configuration or image needs to be updated. (EXPERIMENTAL)]" \ + $opts_help \ + '(--abort-on-container-exit)-d[Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit.]' \ + $opts_no_color \ + $opts_no_deps \ + $opts_force_recreate \ + $opts_no_recreate \ + $opts_no_build \ + "(--no-build)--build[Build images before starting containers.]" \ + "(-d)--abort-on-container-exit[Stops all containers if any container was stopped. Incompatible with -d.]" \ + '(-t --timeout)'{-t,--timeout}"[Use this timeout in seconds for container shutdown when attached or when containers are already running. (default: 10)]:seconds: " \ + $opts_remove_orphans \ '*:services:__docker-compose_services_all' && ret=0 ;; (version) _arguments \ + $opts_help \ "--short[Shows only Compose's version number.]" && ret=0 ;; (*) - _message 'Unknown sub command' + _message 'Unknown sub command' && ret=1 + ;; esac return ret } -_docker-compose () { +_docker-compose() { # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. if [[ $service != docker-compose ]]; then @@ -262,34 +381,62 @@ _docker-compose () { return fi - local curcontext="$curcontext" state line ret=1 + local curcontext="$curcontext" state line + integer ret=1 typeset -A opt_args _arguments -C \ '(- :)'{-h,--help}'[Get help]' \ - '--verbose[Show more output]' \ - '(- :)'{-v,--version}'[Print version and exit]' \ '(-f --file)'{-f,--file}'[Specify an alternate docker-compose file (default: docker-compose.yml)]:file:_files -g "*.yml"' \ '(-p --project-name)'{-p,--project-name}'[Specify an alternate project name (default: directory name)]:project name:' \ + '--verbose[Show more output]' \ + '(- :)'{-v,--version}'[Print version and exit]' \ + '(-H --host)'{-H,--host}'[Daemon socket to connect to]:host:' \ + '--tls[Use TLS; implied by --tlsverify]' \ + '--tlscacert=[Trust certs signed only by this CA]:ca path:' \ + '--tlscert=[Path to TLS certificate file]:client cert path:' \ + '--tlskey=[Path to TLS key file]:tls key path:' \ + '--tlsverify[Use TLS and verify the remote]' \ + "--skip-hostname-check[Don't check the daemon's hostname against the name specified in the client certificate (for example if your docker host is an IP address)]" \ '(-): :->command' \ '(-)*:: :->option-or-argument' && ret=0 - local counter=1 - #local compose_file compose_project - while [ $counter -lt ${#words[@]} ]; do - case "${words[$counter]}" in - -f|--file) - (( counter++ )) - compose_file="${words[$counter]}" - ;; - -p|--project-name) - (( counter++ )) - compose_project="${words[$counter]}" - ;; - *) - ;; - esac - (( counter++ )) + local -a relevant_compose_flags relevant_docker_flags compose_options docker_options + + relevant_compose_flags=( + "--file" "-f" + "--host" "-H" + "--project-name" "-p" + "--tls" + "--tlscacert" + "--tlscert" + "--tlskey" + "--tlsverify" + "--skip-hostname-check" + ) + + relevant_docker_flags=( + "--host" "-H" + "--tls" + "--tlscacert" + "--tlscert" + "--tlskey" + "--tlsverify" + ) + + for k in "${(@k)opt_args}"; do + if [[ -n "${relevant_docker_flags[(r)$k]}" ]]; then + docker_options+=$k + if [[ -n "$opt_args[$k]" ]]; then + docker_options+=$opt_args[$k] + fi + fi + if [[ -n "${relevant_compose_flags[(r)$k]}" ]]; then + compose_options+=$k + if [[ -n "$opt_args[$k]" ]]; then + compose_options+=$opt_args[$k] + fi + fi done case $state in diff --git a/plugins/docker-compose/docker-compose.plugin.zsh b/plugins/docker-compose/docker-compose.plugin.zsh new file mode 100644 index 0000000000000..351e77824c46b --- /dev/null +++ b/plugins/docker-compose/docker-compose.plugin.zsh @@ -0,0 +1,13 @@ +# Authors: +# https://github.com/tristola +# +# Docker-compose related zsh aliases + +# Aliases ################################################################### + +alias dcup='docker-compose up' +alias dcb='docker-compose build' +alias dcrm='docker-compose rm' +alias dcps='docker-compose ps' +alias dcstop='docker-compose stop' +alias dcrestart='docker-compose restart' diff --git a/plugins/docker/README.md b/plugins/docker/README.md index 231a6dcf5d1fc..1615f75f5fe57 100644 --- a/plugins/docker/README.md +++ b/plugins/docker/README.md @@ -1,19 +1,5 @@ ## Docker autocomplete plugin -- Adds autocomplete options for all docker commands. -- Will also show containerIDs and Image names where applicable - -####Shows help for all commands -![General Help](http://i.imgur.com/tUBO9jh.png "Help for all commands") - - -####Shows your downloaded images where applicable -![Images](http://i.imgur.com/R8ZsWO1.png "Images") - - -####Shows your running containers where applicable -![Containers](http://i.imgur.com/WQtbheg.png "Containers") - - - -Maintainer : Ahmed Azaan ([@aeonazaan](https://twitter.com/aeonazaan)) +A copy of the completion script from the +[docker](https://github.com/docker/docker/tree/master/contrib/completion/zsh) +git repo. diff --git a/plugins/docker/_docker b/plugins/docker/_docker index a82a31ad3441f..66dfeea9ef50a 100644 --- a/plugins/docker/_docker +++ b/plugins/docker/_docker @@ -1,439 +1,2144 @@ -#compdef docker +#compdef docker dockerd +# +# zsh completion for docker (http://docker.com) +# +# version: 0.3.0 +# github: https://github.com/felixr/docker-zsh-completion +# +# contributors: +# - Felix Riedel +# - Steve Durrheimer +# - Vincent Bernat +# +# license: +# +# Copyright (c) 2013, Felix Riedel +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# -# Docker autocompletion for oh-my-zsh -# Requires: Docker installed -# Author: Azaan (@aeonazaan) -# Updates: Bob Maerten (@bobmaerten) for Docker v0.9+ -# Paul van den Berg (@bergvandenp) for Docker v1.3+ +# Short-option stacking can be enabled with: +# zstyle ':completion:*:*:docker:*' option-stacking yes +# zstyle ':completion:*:*:docker-*:*' option-stacking yes +__docker_arguments() { + if zstyle -t ":completion:${curcontext}:" option-stacking; then + print -- -s + fi +} + +__docker_get_containers() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local kind type line s + declare -a running stopped lines args names + + kind=$1; shift + type=$1; shift + [[ $kind = (stopped|all) ]] && args=($args -a) + + lines=(${(f)"$(_call_program commands docker $docker_options ps --format 'table' --no-trunc $args)"}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 # Last column, should go to the end of the line + lines=(${lines[2,-1]}) + + # Container ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}[0,12]}" + s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + fi + + # Names: we only display the one without slash. All other names + # are generated and may clutter the completion. However, with + # Swarm, all names may be prefixed by the swarm node name. + if [[ $type = (names|all) ]]; then + for line in $lines; do + names=(${(ps:,:)${${line[${begin[NAMES]},${end[NAMES]}]}%% *}}) + # First step: find a common prefix and strip it (swarm node case) + (( ${#${(u)names%%/*}} == 1 )) && names=${names#${names[1]%%/*}/} + # Second step: only keep the first name without a / + s=${${names:#*/*}[1]} + # If no name, well give up. + (( $#s != 0 )) || continue + s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" + s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" + if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then + stopped=($stopped $s) + else + running=($running $s) + fi + done + fi + [[ $kind = (running|all) ]] && _describe -t containers-running "running containers" running "$@" && ret=0 + [[ $kind = (stopped|all) ]] && _describe -t containers-stopped "stopped containers" stopped "$@" && ret=0 + return ret +} + +__docker_stoppedcontainers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers stopped all "$@" +} + +__docker_runningcontainers() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers running all "$@" +} -# ----- Helper functions -# Output a selectable list of all running docker containers __docker_containers() { - declare -a cont_cmd - cont_cmd=($(docker ps | awk 'NR>1{print $NF":[CON("$1")"$2"("$3")]"}')) - if [[ 'X$cont_cmd' != 'X' ]] - _describe 'containers' cont_cmd + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all all "$@" +} + +__docker_containers_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all ids "$@" } -# Output a selectable list of all containers, even not running -__docker_all_containers() { - declare -a cont_cmd - cont_cmd=($(docker ps -a | awk 'NR>1{print $NF":[CON("$1")"$2"("$3")]"}')) - if [[ 'X$cont_cmd' != 'X' ]] - _describe 'containers' cont_cmd +__docker_containers_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_containers all names "$@" +} + +__docker_complete_info_plugins() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + emulate -L zsh + setopt extendedglob + local -a plugins + plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) + _describe -t plugins "$1 plugins" plugins && ret=0 + return ret } -# output a selectable list of all docker images __docker_images() { - declare -a img_cmd - img_cmd=($(docker images | awk 'NR>1{print $1}'| sed 's/:/\\:/g')) - _describe 'images' img_cmd -} - -# ----- Commands -# Seperate function for each command, makes extension easier later -# --------------------------- -__attach() { - _arguments \ - '--no-stdin[Do not attach STDIN]' \ - '--sig-proxy[Proxify all received signal to the process (even in non-tty mode)]' - __docker_containers -} - -__build() { - _arguments \ - '--no-cache[Do not use cache when building the image]' \ - '(-q,--quiet)'{-q,--quiet}'[Suppress the verbose output generated by the containers]' \ - '--rm[Remove intermediate containers after a successful build]' \ - '(-t,--tag=)'{-t,--tag=}'[Repository name (and optionally a tag) to be applied to the resulting image in case of success]' \ - '*:files:_files' -} - -__commit() { - _arguments \ - '(-a,--author=)'{-a,--author=}'[Author (e.g. "John Hannibal Smith ")]' \ - '(-c,--change=)'{-c,--change=}'[Apply Dockerfile instruction to the created image]' \ - '(-m,--message=)'{-m,--message=}'[Commit message]' \ - '(-p,--pause=)'{-p,--pause=}'[Pause container during commit]' \ -} - -__cp() { - __docker_containers -} - -__create() { - _arguments \ - '(-P,--publish-all=)'{-P,--publish-all=}'[Publish all exposed ports to the host interfaces]' \ - '(-a,--attach=)'{-a,--attach=}'[Attach to STDIN, STDOUT or STDERR]' \ - '--add-host=[Add a custom host-to-IP mapping]' \ - '--cap-add=[Add Linux capabilities]' \ - '--cap-drop=[Drop Linux capabilities]' \ - '--cpuset-cpus=[CPUs in which to allow execution (0-3, 0,1)]' \ - '(-c,--cpu-shares=)'{-c,--cpu-shares=}'[CPU shares (relative weight)]' \ - '--cidfile=[Write the container ID to the file]' \ - '--device=[Add a host device to the container]' \ - '--dns=[Set custom dns servers]' \ - '--dns-search=[Set custom DNS search domains]' \ - '(-e,--env=)'{-e,--env=}'[Set environment variables]' \ - '--env-file=[Read in a file of environment variables]' \ - '--entrypoint=[Overwrite the default entrypoint of the image]' \ - '--expose=[Expose a port from the container without publishing it to your host]' \ - '(-h,--hostname=)'{-h,--hostname=}'[Container host name]' \ - '(-i,--interactive=)'{-i,--interactive=}'[Keep STDIN open even if not attached]' \ - '--ipc=[IPC namespace to use]' \ - '(-l,--label=)'{-l,--label=}'[Set meta data on a container]' \ - '--link=[Add link to another container (name:alias)]' \ - '--log-driver=[Logging driver for the container]' \ - '--lxc-conf=[Add custom LXC options]' \ - '--mac-address=[Container MAC address (e.g. 92:d0:c6:0a:29:33)]' \ - '(-m,--memory=)'{-m,--memory=}'[Memory limit (format: , where unit = b, k, m or g)]' \ - '--net=[Set the Network mode for the container]' \ - '--name=[Assign a name to the container]' \ - '--pid=[PID namespace to use]' \ - '(-p,--publish=)'{-p,--publish=}'[Publish a container''s port to the host (format: ip:hostPort:containerPort/protocol)]' \ - '--privileged=[Give extended privileges to this container]' \ - '--restart=[Restart policy to apply when a container exits]' \ - '--security-opt=[Security Options]' \ - '--sig-proxy=[Proxify all received signal to the process (even in non-tty mode)]' \ - '(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-tty]' \ - '(-u,--user=)'{-u,--user=}'[Username or UID]' \ - '--ulimit=[Ulimit options]' \ - '(-v,--volume=)'{-v,--volume=}'[Bind mount a volume (e.g. -v /host:/container or -v /container)]' \ - '--volumes-from=[Mount volumes from the specified container(s)]' \ - '(-w,--workdir=)'{-w,--workdir=}'[Working directory inside the container]' - __docker_images + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a images + images=(${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/(#b)([^ ]##) ##([^ ]##) ##([^ ]##)*/${match[3]}:${(r:15:: :::)match[2]} in ${match[1]}}) + _describe -t docker-images "images" images && ret=0 + __docker_repositories_with_tags && ret=0 + return ret +} + +__docker_repositories() { + [[ $PREFIX = -* ]] && return 1 + declare -a repos + repos=(${${${(f)"$(_call_program commands docker $docker_options images)"}%% *}[2,-1]}) + repos=(${repos#}) + _describe -t docker-repos "repositories" repos +} + +__docker_repositories_with_tags() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a repos onlyrepos matched + declare m + repos=(${${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/ ##/:::}%% *}) + repos=(${${repos%:::}#}) + # Check if we have a prefix-match for the current prefix. + onlyrepos=(${repos%::*}) + for m in $onlyrepos; do + [[ ${PREFIX##${~~m}} != ${PREFIX} ]] && { + # Yes, complete with tags + repos=(${${repos/:::/:}/:/\\:}) + _describe -t docker-repos-with-tags "repositories with tags" repos && ret=0 + return ret + } + done + # No, only complete repositories + onlyrepos=(${${repos%:::*}/:/\\:}) + _describe -t docker-repos "repositories" onlyrepos -qS : && ret=0 + + return ret +} + +__docker_search() { + [[ $PREFIX = -* ]] && return 1 + local cache_policy + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + local searchterm cachename + searchterm="${words[$CURRENT]%/}" + cachename=_docker-search-$searchterm + + local expl + local -a result + if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \ + && ! _retrieve_cache ${cachename#_}; then + _message "Searching for ${searchterm}..." + result=(${${${(f)"$(_call_program commands docker $docker_options search $searchterm)"}%% *}[2,-1]}) + _store_cache ${cachename#_} result + fi + _wanted dockersearch expl 'available images' compadd -a result +} + +__docker_get_log_options() { + [[ $PREFIX = -* ]] && return 1 + + integer ret=1 + local log_driver=${opt_args[--log-driver]:-"all"} + local -a awslogs_options fluentd_options gelf_options journald_options json_file_options syslog_options splunk_options + + awslogs_options=("awslogs-region" "awslogs-group" "awslogs-stream") + fluentd_options=("env" "fluentd-address" "fluentd-async-connect" "fluentd-buffer-limit" "fluentd-retry-wait" "fluentd-max-retries" "labels" "tag") + gcplogs_options=("env" "gcp-log-cmd" "gcp-project" "labels") + gelf_options=("env" "gelf-address" "gelf-compression-level" "gelf-compression-type" "labels" "tag") + journald_options=("env" "labels" "tag") + json_file_options=("env" "labels" "max-file" "max-size") + syslog_options=("env" "labels" "syslog-address" "syslog-facility" "syslog-format" "syslog-tls-ca-cert" "syslog-tls-cert" "syslog-tls-key" "syslog-tls-skip-verify" "tag") + splunk_options=("env" "labels" "splunk-caname" "splunk-capath" "splunk-format" "splunk-index" "splunk-insecureskipverify" "splunk-source" "splunk-sourcetype" "splunk-token" "splunk-url" "splunk-verify-connection" "tag") + + [[ $log_driver = (awslogs|all) ]] && _describe -t awslogs-options "awslogs options" awslogs_options "$@" && ret=0 + [[ $log_driver = (fluentd|all) ]] && _describe -t fluentd-options "fluentd options" fluentd_options "$@" && ret=0 + [[ $log_driver = (gcplogs|all) ]] && _describe -t gcplogs-options "gcplogs options" gcplogs_options "$@" && ret=0 + [[ $log_driver = (gelf|all) ]] && _describe -t gelf-options "gelf options" gelf_options "$@" && ret=0 + [[ $log_driver = (journald|all) ]] && _describe -t journald-options "journald options" journald_options "$@" && ret=0 + [[ $log_driver = (json-file|all) ]] && _describe -t json-file-options "json-file options" json_file_options "$@" && ret=0 + [[ $log_driver = (syslog|all) ]] && _describe -t syslog-options "syslog options" syslog_options "$@" && ret=0 + [[ $log_driver = (splunk|all) ]] && _describe -t splunk-options "splunk options" splunk_options "$@" && ret=0 + + return ret +} + +__docker_log_drivers() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + drivers=(awslogs etwlogs fluentd gcplogs gelf journald json-file none splunk syslog) + _describe -t log-drivers "log drivers" drivers && ret=0 + return ret +} + +__docker_log_options() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (syslog-format) + syslog_format_opts=('rfc3164' 'rfc5424' 'rfc5424micro') + _describe -t syslog-format-opts "Syslog format Options" syslog_format_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + __docker_get_log_options -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_detach_keys() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + compset -P "*," + keys=(${:-{a-z}}) + ctrl_keys=(${:-ctrl-{{a-z},{@,'[','\\','^',']',_}}}) + _describe -t detach_keys "[a-z]" keys -qS "," && ret=0 + _describe -t detach_keys-ctrl "'ctrl-' + 'a-z @ [ \\\\ ] ^ _'" ctrl_keys -qS "," && ret=0 +} + +__docker_complete_pid() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local -a opts vopts + + opts=('host') + vopts=('container') + + if compset -P '*:'; then + case "${${words[-1]%:*}#*=}" in + (container) + __docker_runningcontainers && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t pid-value-opts "PID Options with value" vopts -qS ":" && ret=0 + _describe -t pid-opts "PID Options" opts && ret=0 + fi + + return ret +} + +__docker_complete_runtimes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + emulate -L zsh + setopt extendedglob + local -a runtimes_opts + runtimes_opts=(${(ps: :)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Runtimes: }%%$'\n'^ *}}}) + _describe -t runtimes-opts "runtimes options" runtimes_opts && ret=0 +} + +__docker_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (ancestor) + __docker_images && ret=0 + ;; + (before|since) + __docker_containers && ret=0 + ;; + (id) + __docker_containers_ids && ret=0 + ;; + (name) + __docker_containers_names && ret=0 + ;; + (network) + __docker_networks && ret=0 + ;; + (status) + status_opts=('created' 'dead' 'exited' 'paused' 'restarting' 'running' 'removing') + _describe -t status-filter-opts "Status Filter Options" status_opts && ret=0 + ;; + (volume) + __docker_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('ancestor' 'before' 'exited' 'id' 'label' 'name' 'network' 'since' 'status' 'volume') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_complete_search_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a boolean_opts opts + + boolean_opts=('true' 'false') + opts=('is-automated' 'is-official' 'stars') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (is-automated|is-official) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret } -__diff() { - __docker_containers +__docker_complete_images_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a boolean_opts opts + + boolean_opts=('true' 'false') + opts=('before' 'dangling' 'label' 'since') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (before|since) + __docker_images && ret=0 + ;; + (dangling) + _describe -t boolean-filter-opts "filter options" boolean_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret } -__events() { - _arguments \ - '--since=[Show previously created events and then stream.]' +__docker_complete_events_filter() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a opts + + opts=('container' 'daemon' 'event' 'image' 'label' 'network' 'type' 'volume') + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (container) + __docker_containers && ret=0 + ;; + (daemon) + emulate -L zsh + setopt extendedglob + local -a daemon_opts + daemon_opts=( + ${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Name: }%%$'\n'^ *}} + ${${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'ID: }%%$'\n'^ *}}//:/\\:} + ) + _describe -t daemon-filter-opts "daemon filter options" daemon_opts && ret=0 + ;; + (event) + local -a event_opts + event_opts=('attach' 'commit' 'connect' 'copy' 'create' 'delete' 'destroy' 'detach' 'die' 'disconnect' 'exec_create' 'exec_detach' + 'exec_start' 'export' 'import' 'kill' 'load' 'mount' 'oom' 'pause' 'pull' 'push' 'reload' 'rename' 'resize' 'restart' 'save' 'start' + 'stop' 'tag' 'top' 'unmount' 'unpause' 'untag' 'update') + _describe -t event-filter-opts "event filter options" event_opts && ret=0 + ;; + (image) + __docker_images && ret=0 + ;; + (network) + __docker_networks && ret=0 + ;; + (type) + local -a type_opts + type_opts=('container' 'daemon' 'image' 'network' 'volume') + _describe -t type-filter-opts "type filter options" type_opts && ret=0 + ;; + (volume) + __docker_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret } -__export() { - __docker_containers +# BO network + +__docker_network_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (driver) + __docker_complete_info_plugins Network && ret=0 + ;; + (id) + __docker_networks_ids && ret=0 + ;; + (name) + __docker_networks_names && ret=0 + ;; + (type) + type_opts=('builtin' 'custom') + _describe -t type-filter-opts "Type Filter Options" type_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('driver' 'id' 'label' 'name' 'type') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret } -__history() { - _arguments \ - '--no-trunc=[Don''t truncate output]' \ - '(-q,--quiet)'{-q,--quiet}'[Only show numeric IDs]' - __docker_images +__docker_get_networks() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines networks + + type=$1; shift + + lines=(${(f)"$(_call_program commands docker $docker_options network ls)"}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Network ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[NETWORK ID]},${end[NETWORK ID]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + networks=($networks $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + networks=($networks $s) + done + fi + + _describe -t networks-list "networks" networks "$@" && ret=0 + return ret } -__images() { - _arguments \ - '(-a,--all)'{-a,--all}'[Show all images (by default filter out the intermediate images used to build)]' \ - '--no-trunc[Don''t truncate output]' \ - '(-q,--quiet=)'{-q,--quiet=}'[Only show numeric IDs]' \ - '(-t,--tree=)'{-t,--tree=}'[Output graph in tree format]' \ - '(-v,--viz=)'{-v,--viz=}'[Output graph in graphviz format]' - __docker_images +__docker_networks() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks all "$@" } -__import() { - _arguments '*:files:_files' +__docker_networks_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks ids "$@" } -__info() { - # no arguments -} - -__inspect() { - __docker_images - __docker_all_containers -} - -__kill() { - _arguments \ - '(-s,--signal=)'{-s,--signal=}'[KILL Signal]' - __docker_containers -} - -__load() { - _arguments '*:files:_files' -} - -__login() { - _arguments \ - '(-e,--email=)'{-e,-email=}'[Email]' \ - '(-p,--password=)'{-p,-password=}'[Password]' \ - '(-u,--username=)'{-u,-username=}'[Username]' -} - -__logs() { - _arguments \ - '(-f,--follow)'{-f,-follow}'[Follow log output]' - __docker_containers -} - -__port() { - __docker_containers -} - -__top() { - __docker_containers -} - -__ps() { - _arguments \ - '(-a,--all)'{-a,--all}'[Show all containers. Only running containers are shown by default.]' \ - '--before-id=[Show only container created before Id, include non-running ones.]' \ - '(-l,--latest)'{-l,--latest}'[Show only the latest created container, include non-running ones.]' \ - '-n=[Show n last created containers, include non-running ones. default=-1.]' \ - '--no-trunc[Don''t truncate output]' \ - '(-q,--quiet)'{-q,--quiet}'[Only display numeric IDs]' \ - '(-s,--size)'{-s,--size}'[Display sizes]' \ - '--since-id=[Show only containers created since Id, include non-running ones.]' +__docker_networks_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_get_networks names "$@" } -__pull() { - _arguments \ - '(-t,--tag=)'{-t,--tag=}'[Download tagged image in repository]' +__docker_network_commands() { + local -a _docker_network_subcommands + _docker_network_subcommands=( + "connect:Connect a container to a network" + "create:Creates a new network with a name specified by the user" + "disconnect:Disconnects a container from a network" + "inspect:Displays detailed information on a network" + "ls:Lists all the networks created by the user" + "rm:Deletes one or more networks" + ) + _describe -t docker-network-commands "docker network command" _docker_network_subcommands } -__push() { - # no arguments +__docker_network_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (connect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--alias=[Add network-scoped alias for the container]:alias: " \ + "($help)--ip=[Container IPv4 address]:IPv4: " \ + "($help)--ip6=[Container IPv6 address]:IPv6: " \ + "($help)*--link=[Add a link to another container]:link:->link" \ + "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " \ + "($help -)1:network:__docker_networks" \ + "($help -)2:containers:__docker_containers" && ret=0 + + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_runningcontainers -qS ":" && ret=0 + fi + ;; + esac + ;; + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help)*--aux-address[Auxiliary IPv4 or IPv6 addresses used by network driver]:key=IP: " \ + "($help -d --driver)"{-d=,--driver=}"[Driver to manage the Network]:driver:(null host bridge overlay)" \ + "($help)*--gateway=[IPv4 or IPv6 Gateway for the master subnet]:IP: " \ + "($help)--internal[Restricts external access to the network]" \ + "($help)*--ip-range=[Allocate container ip from a sub-range]:IP/mask: " \ + "($help)--ipam-driver=[IP Address Management Driver]:driver:(default)" \ + "($help)*--ipam-opt=[Custom IPAM plugin options]:opt=value: " \ + "($help)--ipv6[Enable IPv6 networking]" \ + "($help)*--label=[Set metadata on a network]:label=value: " \ + "($help)*"{-o=,--opt=}"[Driver specific options]:opt=value: " \ + "($help)*--subnet=[Subnet in CIDR format that represents a network segment]:IP/mask: " \ + "($help -)1:Network Name: " && ret=0 + ;; + (disconnect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:network:__docker_networks" \ + "($help -)2:containers:__docker_containers" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -)*:network:__docker_networks" && ret=0 + ;; + (ls) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--no-trunc[Do not truncate the output]" \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ + "($help)--format=[Pretty-print networks using a Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display numeric IDs]" && ret=0 + case $state in + (filter-options) + __docker_network_complete_ls_filters && ret=0 + ;; + esac + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:network:__docker_networks" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 + ;; + esac + + return ret } -__restart() { - _arguments \ - '(-t,--time=)'{-t,--time=}'[Number of seconds to try to stop for before killing the container. Once killed it will then be restarted. Default=10]' - __docker_containers +# EO network + +# BO node + +__docker_node_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (id) + __docker_complete_nodes_ids && ret=0 + ;; + (membership) + membership_opts=('accepted' 'pending' 'rejected') + _describe -t membership-opts "membership options" membership_opts && ret=0 + ;; + (name) + __docker_complete_nodes_names && ret=0 + ;; + (role) + role_opts=('manager' 'worker') + _describe -t role-opts "role options" role_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'membership' 'name' 'role') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret } -__rm() { - _arguments \ - '(-f,--force=)'{-f,--force=}'[Force removal of running container]' \ - '(-l,--link=)'{-l,--link=}'[Remove the specified link and not the underlying container]' \ - '(-v,--volumes=)'{-v,--volumes=}'[Remove the volumes associated to the container]' - __docker_all_containers +__docker_node_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret } -__rmi() { - _arguments \ - '(-f,--force=)'{-f,--force=}'[Force]' - __docker_images +__docker_nodes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines nodes args + + type=$1; shift + filter=$1; shift + [[ $filter != "none" ]] && args=("-f $filter") + + lines=(${(f)"$(_call_program commands docker $docker_options node ls $args)"}) + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Node ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + nodes=($nodes $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + nodes=($nodes $s) + done + fi + + _describe -t nodes-list "nodes" nodes "$@" && ret=0 + return ret +} + +__docker_complete_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all none "$@" +} + +__docker_complete_nodes_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes ids none "$@" +} + +__docker_complete_nodes_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes names none "$@" +} + +__docker_complete_pending_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "membership=pending" "$@" +} + +__docker_complete_manager_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "role=manager" "$@" } -__run() { - _arguments \ - '(-P,--publish-all=)'{-P,--publish-all=}'[Publish all exposed ports to the host interfaces]' \ - '(-a,--attach=)'{-a,--attach=}'[Attach to STDIN, STDOUT or STDERR]' \ - '--add-host=[Add a custom host-to-IP mapping]' \ - '--cap-add=[Add Linux capabilities]' \ - '--cap-drop=[Drop Linux capabilities]' \ - '--cpuset-cpus=[CPUs in which to allow execution (0-3, 0,1)]' \ - '(-c,--cpu-shares=)'{-c,--cpu-shares=}'[CPU shares (relative weight)]' \ - '--cidfile=[Write the container ID to the file]' \ - '(-d,--detach=)'{-d,--detach=}'[Run container in the background, print new container id]' \ - '--device=[Add a host device to the container]' \ - '--dns=[Set custom dns servers]' \ - '--dns-search=[Set custom DNS search domains]' \ - '(-e,--env=)'{-e,--env=}'[Set environment variables]' \ - '--env-file=[Read in a file of environment variables]' \ - '--entrypoint=[Overwrite the default entrypoint of the image]' \ - '--expose=[Expose a port from the container without publishing it to your host]' \ - '(-h,--hostname=)'{-h,--hostname=}'[Container host name]' \ - '(-i,--interactive=)'{-i,--interactive=}'[Keep STDIN open even if not attached]' \ - '--ipc=[IPC namespace to use]' \ - '(-l,--label=)'{-l,--label=}'[Set meta data on a container]' \ - '--link=[Add link to another container (name:alias)]' \ - '--log-driver=[Logging driver for the container]' \ - '--lxc-conf=[Add custom LXC options]' \ - '--mac-address=[Container MAC address (e.g. 92:d0:c6:0a:29:33)]' \ - '(-m,--memory=)'{-m,--memory=}'[Memory limit (format: , where unit = b, k, m or g)]' \ - '--net=[Set the Network mode for the container]' \ - '--name=[Assign a name to the container]' \ - '--pid=[PID namespace to use]' \ - '(-p,--publish=)'{-p,--publish=}'[Publish a container''s port to the host (format: ip:hostPort:containerPort/protocol)]' \ - '--privileged=[Give extended privileges to this container]' \ - '--restart=[Restart policy to apply when a container exits]' \ - '--rm=[Automatically remove the container when it exits (incompatible with -d)]' \ - '--security-opt=[Security Options]' \ - '--sig-proxy=[Proxify all received signal to the process (even in non-tty mode)]' \ - '(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-tty]' \ - '(-u,--user=)'{-u,--user=}'[Username or UID]' \ - '--ulimit=[Ulimit options]' \ - '(-v,--volume=)'{-v,--volume=}'[Bind mount a volume (e.g. -v /host:/container or -v /container)]' \ - '--volumes-from=[Mount volumes from the specified container(s)]' \ - '(-w,--workdir=)'{-w,--workdir=}'[Working directory inside the container]' - __docker_images -} - -__search() { - _arguments \ - '--no-trunc=[Don''t truncate output]' \ - '-s,--stars=)'{-s,--stars=}'[Only displays with at least xxx stars]' \ - '-t,--trusted=)'{-t,--trusted=}'[Only show trusted builds]' -} - -__save() { - __docker_images -} - -__start() { - _arguments \ - '(-a,--attach=)'{-a,--attach=}'[Attach container''s STDOUT/STDERR and forward all signals to the process]' \ - '(-i,--interactive=)'{-i,--interactive=}'[Attach container''s STDIN]' - __docker_all_containers -} - -__stats() { - __docker_containers -} - -__stop() { - _arguments \ - '(-t,--time=)'{-t,--time=}'[Number of seconds to wait for the container to stop before killing it.]' - __docker_containers -} - -__tag() { - _arguments \ - '(-f,--force=)'{-f,--force=}'[Force]' - __docker_images -} - -__version() { - # no arguments -} - -__wait() { - __docker_containers -} - -__exec() { - _arguments \ - '(-d,--detach=)'{-d,--detach=}'[Detached mode: run command in the background]' \ - '(-i,--interactive=)'{-i,--interactive=}'[Keep STDIN open even if not attached]' \ - '(-t,--tty=)'{-t,--tty=}'[Allocate a pseudo-TTY]' - __docker_containers -} - -# end commands --------- -# ---------------------- - -local -a _1st_arguments -_1st_arguments=( - "attach":"Attach to a running container" - "build":"Build a container from a Dockerfile" - "commit":"Create a new image from a container's changes" - "cp":"Copy files/folders from the containers filesystem to the host path" - "create":"Create new container without running it" - "diff":"Inspect changes on a container's filesystem" - "events":"Get real time events from the server" - "export":"Stream the contents of a container as a tar archive" - "history":"Show the history of an image" - "images":"List images" - "import":"Create a new filesystem image from the contents of a tarball" - "info":"Display system-wide information" - "inspect":"Return low-level information on a container" - "kill":"Kill a running container" - "load":"Load an image from a tar archive" - "login":"Register or Login to the docker registry server" - "logs":"Fetch the logs of a container" - "port":"Lookup the public-facing port which is NAT-ed to PRIVATE_PORT" - "ps":"List containers" - "pull":"Pull an image or a repository from the docker registry server" - "push":"Push an image or a repository to the docker registry server" - "restart":"Restart a running container" - "rm":"Remove one or more containers" - "rmi":"Remove one or more images" - "run":"Run a command in a new container" - "save":"Save an image to a tar archive" - "search":"Search for an image in the docker index" - "start":"Start a stopped container" - "stats":"Display a live stream of one or more containers' resource usage statistics" - "stop":"Stop a running container" - "tag":"Tag an image into a repository" - "top":"Lookup the running processes of a container" - "version":"Show the docker version information" - "wait":"Block until a container stops, then print its exit code" - "exec":"Run a task inside a running container" -) - -_arguments '*:: :->command' - -if (( CURRENT == 1 )); then - _describe -t commands "docker command" _1st_arguments - return -fi - -local -a _command_args -case "$words[1]" in - attach) - __attach ;; - build) - __build ;; - commit) - __commit ;; - cp) - __cp ;; - create) - __create ;; - diff) - __diff ;; - events) - __events ;; - export) - __export ;; - history) - __history ;; - images) - __images ;; - import) - __import ;; - info) - __info ;; - inspect) - __inspect ;; - kill) - __kill ;; - load) - __load ;; - login) - __login ;; - logs) - __logs ;; - port) - __port ;; - ps) - __ps ;; - pull) - __pull ;; - push) - __push ;; - restart) - __restart ;; - rm) - __rm ;; - rmi) - __rmi ;; - run) - __run ;; - save) - __save ;; - search) - __search ;; - stats) - __stats ;; - start) - __start ;; - stop) - __stop ;; - tag) - __tag ;; - top) - __top ;; - version) - __version ;; - wait) - __wait ;; - exec) - __exec ;; -esac +__docker_complete_worker_nodes() { + [[ $PREFIX = -* ]] && return 1 + __docker_nodes all "role=worker" "$@" +} + +__docker_node_commands() { + local -a _docker_node_subcommands + _docker_node_subcommands=( + "demote:Demote a node as manager in the swarm" + "inspect:Display detailed information on one or more nodes" + "ls:List nodes in the swarm" + "promote:Promote a node as manager in the swarm" + "rm:Remove one or more nodes from the swarm" + "ps:List tasks running on a node" + "update:Update a node" + ) + _describe -t docker-node-commands "docker node command" _docker_node_subcommands +} + +__docker_node_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--force[Force remove an active node]" \ + "($help -)*:node:__docker_complete_pending_nodes" && ret=0 + ;; + (demote) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:node:__docker_complete_manager_nodes" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--pretty[Print the information in a human friendly format]" \ + "($help -)*:node:__docker_complete_nodes" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + case $state in + (filter-options) + __docker_node_complete_ls_filters && ret=0 + ;; + esac + ;; + (promote) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:node:__docker_complete_worker_nodes" && ret=0 + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Display all instances]" \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -)1:node:__docker_complete_nodes" && ret=0 + case $state in + (filter-options) + __docker_node_complete_ps_filters && ret=0 + ;; + esac + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--availability=[Availability of the node]:availability:(active pause drain)" \ + "($help)*--label-add=[Add or update a node label]:key=value: " \ + "($help)*--label-rm=[Remove a node label if exists]:label: " \ + "($help)--role=[Role of the node]:role:(manager worker)" \ + "($help -)1:node:__docker_complete_nodes" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_node_commands" && ret=0 + ;; + esac + + return ret +} + +# EO node + +# BO plugin + +__docker_complete_plugins() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines plugins + + lines=(${(f)"$(_call_program commands docker $docker_options plugin ls)"}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Name + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}" + plugins=($plugins $s) + done + + _describe -t plugins-list "plugins" plugins "$@" && ret=0 + return ret +} + +__docker_plugin_commands() { + local -a _docker_plugin_subcommands + _docker_plugin_subcommands=( + "disable:Disable a plugin" + "enable:Enable a plugin" + "inspect:Return low-level information about a plugin" + "install:Install a plugin" + "ls:List plugins" + "push:Push a plugin" + "rm:Remove a plugin" + "set:Change settings for a plugin" + ) + _describe -t docker-plugin-commands "docker plugin command" _docker_plugin_subcommands +} + +__docker_plugin_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (disable|enable|inspect|install|ls|push|rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:plugin:__docker_complete_plugins" && ret=0 + ;; + (set) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:plugin:__docker_complete_plugins" \ + "($help-)*:key=value: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_plugin_commands" && ret=0 + ;; + esac + + return ret +} + +# EO plugin + +# BO service + +__docker_service_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (id) + __docker_complete_services_ids && ret=0 + ;; + (name) + __docker_complete_services_names && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_service_complete_ps_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (desired-state) + state_opts=('accepted' 'running') + _describe -t state-opts "desired state options" state_opts && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('desired-state' 'id' 'label' 'name') + _describe -t filter-opts "filter options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_services() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + local line s + declare -a lines services + + type=$1; shift + + lines=(${(f)"$(_call_program commands docker $docker_options service ls)"}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Service ID + if [[ $type = (ids|all) ]]; then + for line in $lines; do + s="${line[${begin[ID]},${end[ID]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" + services=($services $s) + done + fi + + # Names + if [[ $type = (names|all) ]]; then + for line in $lines; do + s="${line[${begin[NAME]},${end[NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[IMAGE]},${end[IMAGE]}]}%% ##}}" + services=($services $s) + done + fi + + _describe -t services-list "services" services "$@" && ret=0 + return ret +} + +__docker_complete_services() { + [[ $PREFIX = -* ]] && return 1 + __docker_services all "$@" +} + +__docker_complete_services_ids() { + [[ $PREFIX = -* ]] && return 1 + __docker_services ids "$@" +} + +__docker_complete_services_names() { + [[ $PREFIX = -* ]] && return 1 + __docker_services names "$@" +} + +__docker_service_commands() { + local -a _docker_service_subcommands + _docker_service_subcommands=( + "create:Create a new service" + "inspect:Display detailed information on one or more services" + "ls:List services" + "rm:Remove one or more services" + "scale:Scale one or multiple services" + "ps:List the tasks of a service" + "update:Update a service" + ) + _describe -t docker-service-commands "docker service command" _docker_service_subcommands +} + +__docker_service_subcommand() { + local -a _command_args opts_help opts_create_update + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + opts_create_update=( + "($help)*--constraint=[Placement constraints]:constraint: " + "($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)" + "($help)*"{-e=,--env=}"[Set environment variables]:env: " + "($help)*--label=[Service labels]:label: " + "($help)--limit-cpu=[Limit CPUs]:value: " + "($help)--limit-memory=[Limit Memory]:value: " + "($help)--log-driver=[Logging driver for service]:logging driver:__docker_log_drivers" + "($help)*--log-opt=[Logging driver options]:log driver options:__docker_log_options" + "($help)*--mount=[Attach a mount to the service]:mount: " + "($help)--name=[Service name]:name: " + "($help)*--network=[Network attachments]:network: " + "($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: " + "($help)--replicas=[Number of tasks]:replicas: " + "($help)--reserve-cpu=[Reserve CPUs]:value: " + "($help)--reserve-memory=[Reserve Memory]:value: " + "($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)" + "($help)--restart-delay=[Delay between restart attempts]:delay: " + "($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: " + "($help)--restart-window=[Window used to evaluate the restart policy]:window: " + "($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: " + "($help)--update-delay=[Delay between updates]:delay: " + "($help)--update-failure-action=[Action on update failure]:mode:(pause continue)" + "($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: " + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" + "($help)--with-registry-auth[Send registry authentication details to swarm agents]" + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" + ) + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_update \ + "($help)*--container-label=[Container labels]:label: " \ + "($help)--mode=[Service Mode]:mode:(global replicated)" \ + "($help -): :__docker_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help)--pretty[Print the information in a human friendly format]" \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (ls|list) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter output based on conditions provided]:filter:->filter-options" \ + "($help -q --quiet)"{-q,--quiet}"[Only display IDs]" && ret=0 + case $state in + (filter-options) + __docker_service_complete_ls_filters && ret=0 + ;; + esac + ;; + (rm|remove) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:service:__docker_complete_services" && ret=0 + ;; + (scale) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:service:->values" && ret=0 + case $state in + (values) + if compset -P '*='; then + _message 'replicas' && ret=0 + else + __docker_complete_services -qS "=" + fi + ;; + esac + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Display all tasks]" \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ + "($help)--no-resolve[Do not map IDs to Names]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -)1:service:__docker_complete_services" && ret=0 + case $state in + (filter-options) + __docker_service_complete_ps_filters && ret=0 + ;; + esac + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_update \ + "($help)--arg=[Service command args]:arguments: _normal" \ + "($help)*--container-label-add=[Add or update container labels]:label: " \ + "($help)*--container-label-rm=[Remove a container label by its key]:label: " \ + "($help)--image=[Service image tag]:image:__docker_repositories" \ + "($help -)1:service:__docker_complete_services" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_service_commands" && ret=0 + ;; + esac + + return ret +} + +# EO service + +# BO swarm + +__docker_swarm_commands() { + local -a _docker_swarm_subcommands + _docker_swarm_subcommands=( + "init:Initialize a swarm" + "join:Join a swarm as a node and/or manager" + "join-token:Manage join tokens" + "leave:Leave a swarm" + "update:Update the swarm" + ) + _describe -t docker-swarm-commands "docker swarm command" _docker_swarm_subcommands +} + +__docker_swarm_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (init) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--advertise-addr[Advertised address]:ip\:port: " \ + "($help)*--external-ca=[Specifications of one or more certificate signing endpoints]:endpoint: " \ + "($help)--force-new-cluster[Force create a new cluster from current state]" \ + "($help)--listen-addr=[Listen address]:ip\:port: " && ret=0 + ;; + (join) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--advertise-addr[Advertised address]:ip\:port: " \ + "($help)--listen-addr=[Listen address]:ip\:port: " \ + "($help)--token=[Token for entry into the swarm]:secret: " \ + "($help -):host\:port: " && ret=0 + ;; + (join-token) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -q --quiet)"{-q,--quiet}"[Only display token]" \ + "($help)--rotate[Rotate join token]" \ + "($help -):role:(manager worker)" && ret=0 + ;; + (leave) + _arguments $(__docker_arguments) \ + $opts_help && ret=0 + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--cert-expiry=[Validity period for node certificates]:duration: " \ + "($help)--dispatcher-heartbeat=[Dispatcher heartbeat period]:duration: " \ + "($help)--task-history-limit=[Task history retention limit]:limit: " && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_network_commands" && ret=0 + ;; + esac + + return ret +} + +# EO swarm + +# BO volume + +__docker_volume_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (dangling) + dangling_opts=('true' 'false') + _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 + ;; + (driver) + __docker_complete_info_plugins Volume && ret=0 + ;; + (name) + __docker_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('dangling' 'driver' 'label' 'name') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + +__docker_volumes() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + declare -a lines volumes + + lines=(${(f)"$(_call_program commands docker $docker_options volume ls)"}) + + # Parse header line to find columns + local i=1 j=1 k header=${lines[1]} + declare -A begin end + while (( j < ${#header} - 1 )); do + i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) + j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) + k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) + begin[${header[$i,$((j-1))]}]=$i + end[${header[$i,$((j-1))]}]=$k + done + end[${header[$i,$((j-1))]}]=-1 + lines=(${lines[2,-1]}) + + # Names + local line s + for line in $lines; do + s="${line[${begin[VOLUME NAME]},${end[VOLUME NAME]}]%% ##}" + s="$s:${(l:7:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}%% ##}}" + volumes=($volumes $s) + done + + _describe -t volumes-list "volumes" volumes && ret=0 + return ret +} + +__docker_volume_commands() { + local -a _docker_volume_subcommands + _docker_volume_subcommands=( + "create:Create a volume" + "inspect:Display detailed information on one or more volumes" + "ls:List volumes" + "rm:Remove one or more volumes" + ) + _describe -t docker-volume-commands "docker volume command" _docker_volume_subcommands +} + +__docker_volume_subcommand() { + local -a _command_args opts_help + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + + case "$words[1]" in + (create) + _arguments $(__docker_arguments) -A '-*' \ + $opts_help \ + "($help -d --driver)"{-d=,--driver=}"[Volume driver name]:Driver name:(local)" \ + "($help)*--label=[Set metadata for a volume]:label=value: " \ + "($help)*"{-o=,--opt=}"[Driver specific options]:Driver option: " \ + "($help -)1:Volume name: " && ret=0 + ;; + (inspect) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -)1:volume:__docker_volumes" && ret=0 + ;; + (ls) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ + "($help)--format=[Pretty-print volumes using a Go template]:template: " \ + "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 + case $state in + (filter-options) + __docker_volume_complete_ls_filters && ret=0 + ;; + esac + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force the removal of one or more volumes]" \ + "($help -):volume:__docker_volumes" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_volume_commands" && ret=0 + ;; + esac + + return ret +} + +# EO volume + +__docker_caching_policy() { + oldp=( "$1"(Nmh+1) ) # 1 hour + (( $#oldp )) +} + +__docker_commands() { + local cache_policy + + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + if [[ -z "$cache_policy" ]]; then + zstyle ":completion:${curcontext}:" cache-policy __docker_caching_policy + fi + + if ( [[ ${+_docker_subcommands} -eq 0 ]] || _cache_invalid docker_subcommands) \ + && ! _retrieve_cache docker_subcommands; + then + local -a lines + lines=(${(f)"$(_call_program commands docker 2>&1)"}) + _docker_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) + _docker_subcommands=($_docker_subcommands 'daemon:Enable daemon mode' 'help:Show help for a command') + (( $#_docker_subcommands > 2 )) && _store_cache docker_subcommands _docker_subcommands + fi + _describe -t docker-commands "docker command" _docker_subcommands +} + +__docker_subcommand() { + local -a _command_args opts_help opts_build_create_run opts_build_create_run_update opts_create_run opts_create_run_update + local expl help="--help" + integer ret=1 + + opts_help=("(: -)--help[Print usage]") + opts_build_create_run=( + "($help)--cgroup-parent=[Parent cgroup for the container]:cgroup: " + "($help)--isolation=[Container isolation technology]:isolation:(default hyperv process)" + "($help)--disable-content-trust[Skip image verification]" + "($help)*--shm-size=[Size of '/dev/shm' (format is '')]:shm size: " + "($help)*--ulimit=[ulimit options]:ulimit: " + "($help)--userns=[Container user namespace]:user namespace:(host)" + ) + opts_build_create_run_update=( + "($help -c --cpu-shares)"{-c=,--cpu-shares=}"[CPU shares (relative weight)]:CPU shares:(0 10 100 200 500 800 1000)" + "($help)--cpu-period=[Limit the CPU CFS (Completely Fair Scheduler) period]:CPU period: " + "($help)--cpu-quota=[Limit the CPU CFS (Completely Fair Scheduler) quota]:CPU quota: " + "($help)--cpuset-cpus=[CPUs in which to allow execution]:CPUs: " + "($help)--cpuset-mems=[MEMs in which to allow execution]:MEMs: " + "($help -m --memory)"{-m=,--memory=}"[Memory limit]:Memory limit: " + "($help)--memory-swap=[Total memory limit with swap]:Memory limit: " + ) + opts_create_run=( + "($help -a --attach)"{-a=,--attach=}"[Attach to stdin, stdout or stderr]:device:(STDIN STDOUT STDERR)" + "($help)*--add-host=[Add a custom host-to-IP mapping]:host\:ip mapping: " + "($help)*--blkio-weight-device=[Block IO (relative device weight)]:device:Block IO weight: " + "($help)*--cap-add=[Add Linux capabilities]:capability: " + "($help)*--cap-drop=[Drop Linux capabilities]:capability: " + "($help)--cidfile=[Write the container ID to the file]:CID file:_files" + "($help)*--device=[Add a host device to the container]:device:_files" + "($help)*--device-read-bps=[Limit the read rate (bytes per second) from a device]:device:IO rate: " + "($help)*--device-read-iops=[Limit the read rate (IO per second) from a device]:device:IO rate: " + "($help)*--device-write-bps=[Limit the write rate (bytes per second) to a device]:device:IO rate: " + "($help)*--device-write-iops=[Limit the write rate (IO per second) to a device]:device:IO rate: " + "($help)*--dns=[Custom DNS servers]:DNS server: " + "($help)*--dns-opt=[Custom DNS options]:DNS option: " + "($help)*--dns-search=[Custom DNS search domains]:DNS domains: " + "($help)*"{-e=,--env=}"[Environment variables]:environment variable: " + "($help)--entrypoint=[Overwrite the default entrypoint of the image]:entry point: " + "($help)*--env-file=[Read environment variables from a file]:environment file:_files" + "($help)*--expose=[Expose a port from the container without publishing it]: " + "($help)*--group-add=[Add additional groups to run as]:group:_groups" + "($help -h --hostname)"{-h=,--hostname=}"[Container host name]:hostname:_hosts" + "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" + "($help)--ip=[Container IPv4 address]:IPv4: " + "($help)--ip6=[Container IPv6 address]:IPv6: " + "($help)--ipc=[IPC namespace to use]:IPC namespace: " + "($help)*--link=[Add link to another container]:link:->link" + "($help)*--link-local-ip=[Add a link-local address for the container]:IPv4/IPv6: " + "($help)*"{-l=,--label=}"[Container metadata]:label: " + "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_log_drivers" + "($help)*--log-opt=[Log driver specific options]:log driver options:__docker_log_options" + "($help)--mac-address=[Container MAC address]:MAC address: " + "($help)--name=[Container name]:name: " + "($help)--network=[Connect a container to a network]:network mode:(bridge none container host)" + "($help)*--network-alias=[Add network-scoped alias for the container]:alias: " + "($help)--oom-kill-disable[Disable OOM Killer]" + "($help)--oom-score-adj[Tune the host's OOM preferences for containers (accepts -1000 to 1000)]" + "($help)--pids-limit[Tune container pids limit (set -1 for unlimited)]" + "($help -P --publish-all)"{-P,--publish-all}"[Publish all exposed ports]" + "($help)*"{-p=,--publish=}"[Expose a container's port to the host]:port:_ports" + "($help)--pid=[PID namespace to use]:PID namespace:__docker_complete_pid" + "($help)--privileged[Give extended privileges to this container]" + "($help)--read-only[Mount the container's root filesystem as read only]" + "($help)*--security-opt=[Security options]:security option: " + "($help)*--sysctl=-[sysctl options]:sysctl: " + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" + "($help)--tmpfs[mount tmpfs]" + "($help)*-v[Bind mount a volume]:volume: " + "($help)--volume-driver=[Optional volume driver for the container]:volume driver:(local)" + "($help)*--volumes-from=[Mount volumes from the specified container]:volume: " + "($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories" + ) + opts_create_run_update=( + "($help)--blkio-weight=[Block IO (relative weight), between 10 and 1000]:Block IO weight:(10 100 500 1000)" + "($help)--kernel-memory=[Kernel memory limit in bytes]:Memory limit: " + "($help)--memory-reservation=[Memory soft limit]:Memory limit: " + "($help)--restart=[Restart policy]:restart policy:(no on-failure always unless-stopped)" + ) + opts_attach_exec_run_start=( + "($help)--detach-keys=[Escape key sequence used to detach a container]:sequence:__docker_complete_detach_keys" + ) + + case "$words[1]" in + (attach) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help)--no-stdin[Do not attach stdin]" \ + "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ + "($help -):containers:__docker_runningcontainers" && ret=0 + ;; + (build) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_build_create_run \ + $opts_build_create_run_update \ + "($help)*--build-arg[Build-time variables]:=: " \ + "($help -f --file)"{-f=,--file=}"[Name of the Dockerfile]:Dockerfile:_files" \ + "($help)--force-rm[Always remove intermediate containers]" \ + "($help)*--label=[Set metadata for an image]:label=value: " \ + "($help)--no-cache[Do not use cache when building the image]" \ + "($help)--pull[Attempt to pull a newer version of the image]" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress verbose build output]" \ + "($help)--rm[Remove intermediate containers after a successful build]" \ + "($help -t --tag)*"{-t=,--tag=}"[Repository, name and tag for the image]: :__docker_repositories_with_tags" \ + "($help -):path or URL:_directories" && ret=0 + ;; + (commit) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --author)"{-a=,--author=}"[Author]:author: " \ + "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ + "($help -m --message)"{-m=,--message=}"[Commit message]:message: " \ + "($help -p --pause)"{-p,--pause}"[Pause container during commit]" \ + "($help -):container:__docker_containers" \ + "($help -): :__docker_repositories_with_tags" && ret=0 + ;; + (cp) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -L --follow-link)"{-L,--follow-link}"[Always follow symbol link]" \ + "($help -)1:container:->container" \ + "($help -)2:hostpath:_files" && ret=0 + case $state in + (container) + if compset -P "*:"; then + _files && ret=0 + else + __docker_containers -qS ":" && ret=0 + fi + ;; + esac + ;; + (create) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_build_create_run \ + $opts_build_create_run_update \ + $opts_create_run \ + $opts_create_run_update \ + "($help -): :__docker_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_runningcontainers -qS ":" && ret=0 + fi + ;; + esac + + ;; + (daemon) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*--add-runtime=[Register an additional OCI compatible runtime]:runtime:__docker_complete_runtimes" \ + "($help)--api-cors-header=[CORS headers in the remote API]:CORS headers: " \ + "($help)*--authorization-plugin=[Authorization plugins to load]" \ + "($help -b --bridge)"{-b=,--bridge=}"[Attach containers to a network bridge]:bridge:_net_interfaces" \ + "($help)--bip=[Network bridge IP]:IP address: " \ + "($help)--cgroup-parent=[Parent cgroup for all containers]:cgroup: " \ + "($help)--config-file=[Path to daemon configuration file]:Config File:_files" \ + "($help)--containerd=[Path to containerd socket]:socket:_files -g \"*.sock\"" \ + "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ + "($help)--default-gateway[Container default gateway IPv4 address]:IPv4 address: " \ + "($help)--default-gateway-v6[Container default gateway IPv6 address]:IPv6 address: " \ + "($help)--cluster-store=[URL of the distributed storage backend]:Cluster Store:->cluster-store" \ + "($help)--cluster-advertise=[Address or interface name to advertise]:Instance to advertise (host\:port): " \ + "($help)*--cluster-store-opt=[Cluster store options]:Cluster options:->cluster-store-options" \ + "($help)*--dns=[DNS server to use]:DNS: " \ + "($help)*--dns-search=[DNS search domains to use]:DNS search: " \ + "($help)*--dns-opt=[DNS options to use]:DNS option: " \ + "($help)*--default-ulimit=[Default ulimits for containers]:ulimit: " \ + "($help)--disable-legacy-registry[Disable contacting legacy registries]" \ + "($help)*--exec-opt=[Runtime execution options]:runtime execution options: " \ + "($help)--exec-root=[Root directory for execution state files]:path:_directories" \ + "($help)--fixed-cidr=[IPv4 subnet for fixed IPs]:IPv4 subnet: " \ + "($help)--fixed-cidr-v6=[IPv6 subnet for fixed IPs]:IPv6 subnet: " \ + "($help -G --group)"{-G=,--group=}"[Group for the unix socket]:group:_groups" \ + "($help -g --graph)"{-g=,--graph=}"[Root of the Docker runtime]:path:_directories" \ + "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ + "($help)--icc[Enable inter-container communication]" \ + "($help)*--insecure-registry=[Enable insecure registry communication]:registry: " \ + "($help)--ip=[Default IP when binding container ports]" \ + "($help)--ip-forward[Enable net.ipv4.ip_forward]" \ + "($help)--ip-masq[Enable IP masquerading]" \ + "($help)--iptables[Enable addition of iptables rules]" \ + "($help)--ipv6[Enable IPv6 networking]" \ + "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ + "($help)*--label=[Key=value labels]:label: " \ + "($help)--live-restore[Enable live restore of docker when containers are still running]" \ + "($help)--log-driver=[Default driver for container logs]:logging driver:__docker_log_drivers" \ + "($help)*--log-opt=[Default log driver options for containers]:log driver options:__docker_log_options" \ + "($help)--max-concurrent-downloads[Set the max concurrent downloads for each pull]" \ + "($help)--max-concurrent-uploads[Set the max concurrent uploads for each push]" \ + "($help)--mtu=[Network MTU]:mtu:(0 576 1420 1500 9000)" \ + "($help)--oom-score-adjust=[Set the oom_score_adj for the daemon]:oom-score:(-500)" \ + "($help -p --pidfile)"{-p=,--pidfile=}"[Path to use for daemon PID file]:PID file:_files" \ + "($help)--raw-logs[Full timestamps without ANSI coloring]" \ + "($help)*--registry-mirror=[Preferred Docker registry mirror]:registry mirror: " \ + "($help -s --storage-driver)"{-s=,--storage-driver=}"[Storage driver to use]:driver:(aufs btrfs devicemapper overlay overlay2 vfs zfs)" \ + "($help)--selinux-enabled[Enable selinux support]" \ + "($help)*--storage-opt=[Storage driver options]:storage driver options: " \ + "($help)--tls[Use TLS]" \ + "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g \"*.(pem|crt)\"" \ + "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g \"*.(pem|crt)\"" \ + "($help)--tlskey=[Path to TLS key file]:Key file:_files -g \"*.(pem|key)\"" \ + "($help)--tlsverify[Use TLS and verify the remote]" \ + "($help)--userns-remap=[User/Group setting for user namespaces]:user\:group:->users-groups" \ + "($help)--userland-proxy[Use userland proxy for loopback traffic]" && ret=0 + + case $state in + (cluster-store) + if compset -P '*://'; then + _message 'host:port' && ret=0 + else + store=('consul' 'etcd' 'zk') + _describe -t cluster-store "Cluster Store" store -qS "://" && ret=0 + fi + ;; + (cluster-store-options) + if compset -P '*='; then + _files && ret=0 + else + opts=('discovery.heartbeat' 'discovery.ttl' 'kv.cacertfile' 'kv.certfile' 'kv.keyfile' 'kv.path') + _describe -t cluster-store-opts "Cluster Store Options" opts -qS "=" && ret=0 + fi + ;; + (users-groups) + if compset -P '*:'; then + _groups && ret=0 + else + _describe -t userns-default "default Docker user management" '(default)' && ret=0 + _users && ret=0 + fi + ;; + esac + ;; + (diff) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_containers" && ret=0 + ;; + (events) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_events_filter" \ + "($help)--since=[Events created since this timestamp]:timestamp: " \ + "($help)--until=[Events created until this timestamp]:timestamp: " && ret=0 + ;; + (exec) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ + "($help -i --interactive)"{-i,--interactive}"[Keep stdin open even if not attached]" \ + "($help)--privileged[Give extended Linux capabilities to the command]" \ + "($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \ + "($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \ + "($help -):containers:__docker_runningcontainers" \ + "($help -)*::command:->anycommand" && ret=0 + + case $state in + (anycommand) + shift 1 words + (( CURRENT-- )) + _normal && ret=0 + ;; + esac + ;; + (export) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -o --output)"{-o=,--output=}"[Write to a file, instead of stdout]:output file:_files" \ + "($help -)*:containers:__docker_containers" && ret=0 + ;; + (history) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -H --human)"{-H,--human}"[Print sizes and dates in human readable format]" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ + "($help -)*: :__docker_images" && ret=0 + ;; + (images) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all images]" \ + "($help)--digests[Show digests]" \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \ + "($help)--format[Pretty-print containers using a Go template]:template: " \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ + "($help -): :__docker_repositories" && ret=0 + + case $state in + (filter-options) + __docker_complete_images_filters && ret=0 + ;; + esac + ;; + (import) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-c=,--change=}"[Apply Dockerfile instruction to the created image]:Dockerfile:_files" \ + "($help -m --message)"{-m=,--message=}"[Commit message for imported image]:message: " \ + "($help -):URL:(- http:// file://)" \ + "($help -): :__docker_repositories_with_tags" && ret=0 + ;; + (info|version) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " && ret=0 + ;; + (inspect) + local state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --format)"{-f=,--format=}"[Format the output using the given go template]:template: " \ + "($help -s --size)"{-s,--size}"[Display total file sizes if the type is container]" \ + "($help)--type=[Return JSON for specified type]:type:(image container)" \ + "($help -)*: :->values" && ret=0 + + case $state in + (values) + if [[ ${words[(r)--type=container]} == --type=container ]]; then + __docker_containers && ret=0 + elif [[ ${words[(r)--type=image]} == --type=image ]]; then + __docker_images && ret=0 + else + __docker_images && __docker_containers && ret=0 + fi + ;; + esac + ;; + (kill) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -s --signal)"{-s=,--signal=}"[Signal to send]:signal:_signals" \ + "($help -)*:containers:__docker_runningcontainers" && ret=0 + ;; + (load) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -i --input)"{-i=,--input=}"[Read from tar archive file]:archive file:_files -g \"*.((tar|TAR)(.gz|.GZ|.Z|.bz2|.lzma|.xz|)|(tbz|tgz|txz))(-.)\"" \ + "($help -q --quiet)"{-q,--quiet}"[Suppress the load output]" && ret=0 + ;; + (login) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -p --password)"{-p=,--password=}"[Password]:password: " \ + "($help -u --user)"{-u=,--user=}"[Username]:username: " \ + "($help -)1:server: " && ret=0 + ;; + (logout) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:server: " && ret=0 + ;; + (logs) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--details[Show extra details provided to logs]" \ + "($help -f --follow)"{-f,--follow}"[Follow log output]" \ + "($help -s --since)"{-s=,--since=}"[Show logs since this timestamp]:timestamp: " \ + "($help -t --timestamps)"{-t,--timestamps}"[Show timestamps]" \ + "($help)--tail=[Output the last K lines]:lines:(1 10 20 50 all)" \ + "($help -)*:containers:__docker_containers" && ret=0 + ;; + (network) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_network_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_network_subcommand && ret=0 + ;; + esac + ;; + (node) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_node_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_node_subcommand && ret=0 + ;; + esac + ;; + (pause|unpause) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_runningcontainers" && ret=0 + ;; + (plugin) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_plugin_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_plugin_subcommand && ret=0 + ;; + esac + ;; + (port) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:containers:__docker_runningcontainers" \ + "($help -)2:port:_ports" && ret=0 + ;; + (ps) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all containers]" \ + "($help)--before=[Show only container created before...]:containers:__docker_containers" \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:__docker_complete_ps_filters" \ + "($help)--format[Pretty-print containers using a Go template]:template: " \ + "($help -l --latest)"{-l,--latest}"[Show only the latest created container]" \ + "($help -n --last)"{-n=,--last=}"[Show n last created containers (includes all states)]:n:(1 5 10 25 50)" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -q --quiet)"{-q,--quiet}"[Only show numeric IDs]" \ + "($help -s --size)"{-s,--size}"[Display total file sizes]" \ + "($help)--since=[Show only containers created since...]:containers:__docker_containers" && ret=0 + ;; + (pull) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all-tags)"{-a,--all-tags}"[Download all tagged images]" \ + "($help)--disable-content-trust[Skip image verification]" \ + "($help -):name:__docker_search" && ret=0 + ;; + (push) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)--disable-content-trust[Skip image signing]" \ + "($help -): :__docker_images" && ret=0 + ;; + (rename) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):old name:__docker_containers" \ + "($help -):new name: " && ret=0 + ;; + (restart|stop) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -t --time)"{-t=,--time=}"[Number of seconds to try to stop for before killing the container]:seconds to before killing:(1 5 10 30 60)" \ + "($help -)*:containers:__docker_runningcontainers" && ret=0 + ;; + (rm) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force removal]" \ + "($help -l --link)"{-l,--link}"[Remove the specified link and not the underlying container]" \ + "($help -v --volumes)"{-v,--volumes}"[Remove the volumes associated to the container]" \ + "($help -)*:containers:->values" && ret=0 + case $state in + (values) + if [[ ${words[(r)-f]} == -f || ${words[(r)--force]} == --force ]]; then + __docker_containers && ret=0 + else + __docker_stoppedcontainers && ret=0 + fi + ;; + esac + ;; + (rmi) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -f --force)"{-f,--force}"[Force removal]" \ + "($help)--no-prune[Do not delete untagged parents]" \ + "($help -)*: :__docker_images" && ret=0 + ;; + (run) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_build_create_run \ + $opts_build_create_run_update \ + $opts_create_run \ + $opts_create_run_update \ + $opts_attach_exec_run_start \ + "($help -d --detach)"{-d,--detach}"[Detached mode: leave the container running in the background]" \ + "($help)--health-cmd=[Command to run to check health]:command: " \ + "($help)--health-interval=[Time between running the check]:time: " \ + "($help)--health-retries=[Consecutive failures needed to report unhealthy]:retries:(1 2 3 4 5)" \ + "($help)--health-timeout=[Maximum time to allow one check to run]:time: " \ + "($help)--no-healthcheck[Disable any container-specified HEALTHCHECK]" \ + "($help)--rm[Remove intermediate containers when it exits]" \ + "($help)--runtime=[Name of the runtime to be used for that container]:runtime:__docker_complete_runtimes" \ + "($help)--sig-proxy[Proxy all received signals to the process (non-TTY mode only)]" \ + "($help)--stop-signal=[Signal to kill a container]:signal:_signals" \ + "($help)--storage-opt=[Storage driver options for the container]:storage options:->storage-opt" \ + "($help -): :__docker_images" \ + "($help -):command: _command_names -e" \ + "($help -)*::arguments: _normal" && ret=0 + + case $state in + (link) + if compset -P "*:"; then + _wanted alias expl "Alias" compadd -E "" && ret=0 + else + __docker_runningcontainers -qS ":" && ret=0 + fi + ;; + (storage-opt) + if compset -P "*="; then + _message "value" && ret=0 + else + opts=('size') + _describe -t filter-opts "storage options" opts -qS "=" && ret=0 + fi + ;; + esac + + ;; + (save) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -o --output)"{-o=,--output=}"[Write to file]:file:_files" \ + "($help -)*: :__docker_images" && ret=0 + ;; + (search) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help)*"{-f=,--filter=}"[Filter values]:filter:->filter-options" \ + "($help)--limit=[Maximum returned search results]:limit:(1 5 10 25 50)" \ + "($help)--no-trunc[Do not truncate output]" \ + "($help -):term: " && ret=0 + + case $state in + (filter-options) + __docker_complete_search_filters && ret=0 + ;; + esac + ;; + (service) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_service_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_service_subcommand && ret=0 + ;; + esac + ;; + (start) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_attach_exec_run_start \ + "($help -a --attach)"{-a,--attach}"[Attach container's stdout/stderr and forward all signals]" \ + "($help -i --interactive)"{-i,--interactive}"[Attach container's stding]" \ + "($help -)*:containers:__docker_stoppedcontainers" && ret=0 + ;; + (stats) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -a --all)"{-a,--all}"[Show all containers (default shows just running)]" \ + "($help)--no-stream[Disable streaming stats and only pull the first result]" \ + "($help -)*:containers:__docker_runningcontainers" && ret=0 + ;; + (swarm) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_swarm_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_swarm_subcommand && ret=0 + ;; + esac + ;; + (tag) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -):source:__docker_images"\ + "($help -):destination:__docker_repositories_with_tags" && ret=0 + ;; + (top) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)1:containers:__docker_runningcontainers" \ + "($help -)*:: :->ps-arguments" && ret=0 + case $state in + (ps-arguments) + _ps && ret=0 + ;; + esac + + ;; + (update) + _arguments $(__docker_arguments) \ + $opts_help \ + $opts_create_run_update \ + $opts_build_create_run_update \ + "($help -)*: :->values" && ret=0 + + case $state in + (values) + if [[ ${words[(r)--kernel-memory*]} = (--kernel-memory*) ]]; then + __docker_stoppedcontainers && ret=0 + else + __docker_containers && ret=0 + fi + ;; + esac + ;; + (volume) + local curcontext="$curcontext" state + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + case $state in + (command) + __docker_volume_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-${words[-1]}: + __docker_volume_subcommand && ret=0 + ;; + esac + ;; + (wait) + _arguments $(__docker_arguments) \ + $opts_help \ + "($help -)*:containers:__docker_runningcontainers" && ret=0 + ;; + (help) + _arguments $(__docker_arguments) ":subcommand:__docker_commands" && ret=0 + ;; + esac + + return ret +} + +_docker() { + # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. + # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. + if [[ $service != docker ]]; then + _call_function - _$service + return + fi + + local curcontext="$curcontext" state line help="-h --help" + integer ret=1 + typeset -A opt_args + + _arguments $(__docker_arguments) -C \ + "(: -)"{-h,--help}"[Print usage]" \ + "($help)--config[Location of client config files]:path:_directories" \ + "($help -D --debug)"{-D,--debug}"[Enable debug mode]" \ + "($help -H --host)"{-H=,--host=}"[tcp://host:port to bind/connect to]:host: " \ + "($help -l --log-level)"{-l=,--log-level=}"[Logging level]:level:(debug info warn error fatal)" \ + "($help)--tls[Use TLS]" \ + "($help)--tlscacert=[Trust certs signed only by this CA]:PEM file:_files -g "*.(pem|crt)"" \ + "($help)--tlscert=[Path to TLS certificate file]:PEM file:_files -g "*.(pem|crt)"" \ + "($help)--tlskey=[Path to TLS key file]:Key file:_files -g "*.(pem|key)"" \ + "($help)--tlsverify[Use TLS and verify the remote]" \ + "($help)--userland-proxy[Use userland proxy for loopback traffic]" \ + "($help -v --version)"{-v,--version}"[Print version information and quit]" \ + "($help -): :->command" \ + "($help -)*:: :->option-or-argument" && ret=0 + + local host=${opt_args[-H]}${opt_args[--host]} + local config=${opt_args[--config]} + local docker_options="${host:+--host $host} ${config:+--config $config}" + + case $state in + (command) + __docker_commands && ret=0 + ;; + (option-or-argument) + curcontext=${curcontext%:*:*}:docker-$words[1]: + __docker_subcommand && ret=0 + ;; + esac + + return ret +} + +_dockerd() { + integer ret=1 + words[1]='daemon' + __docker_subcommand && ret=0 + return ret +} + +_docker "$@" + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 4 +# indent-tabs-mode: nil +# sh-basic-offset: 4 +# End: +# vim: ft=zsh sw=4 ts=4 et diff --git a/plugins/droplr/README.md b/plugins/droplr/README.md new file mode 100644 index 0000000000000..cfbec25edaa37 --- /dev/null +++ b/plugins/droplr/README.md @@ -0,0 +1,19 @@ +# droplr + +Use [Droplr](https://droplr.com/) from the comand line to upload files and shorten +links. It needs to have [Droplr.app](https://droplr.com/apps) installed and logged +in. MacOS only. + +To use it, add `droplr` to the `$plugins` variable in your zshrc file: + +```zsh +plugins=(... droplr) +``` + +Author: [Fabio Fernandes](https://github.com/fabiofl) + +## Examples + +- Upload a file: `droplr ./path/to/file/` + +- Shorten a link: `droplr http://example.com` diff --git a/plugins/droplr/droplr.plugin.zsh b/plugins/droplr/droplr.plugin.zsh new file mode 100644 index 0000000000000..296a8b98b0032 --- /dev/null +++ b/plugins/droplr/droplr.plugin.zsh @@ -0,0 +1,15 @@ +# Only compatible with MacOS +[[ "$OSTYPE" == darwin* ]] || return + +droplr() { + if [[ $# -eq 0 ]]; then + echo You need to specify a parameter. >&2 + return 1 + fi + + if [[ "$1" =~ ^http[|s]:// ]]; then + osascript -e "tell app 'Droplr' to shorten '$1'" + else + open -ga /Applications/Droplr.app "$1" + fi +} diff --git a/plugins/emacs/emacs.plugin.zsh b/plugins/emacs/emacs.plugin.zsh index a3f0085a826ba..c102a5a1e2816 100644 --- a/plugins/emacs/emacs.plugin.zsh +++ b/plugins/emacs/emacs.plugin.zsh @@ -10,7 +10,7 @@ # - Configuration changes made at runtime are applied to all frames. -if "$ZSH/tools/require_tool.sh" emacs 23 2>/dev/null ; then +if "$ZSH/tools/require_tool.sh" emacs 24 2>/dev/null ; then export EMACS_PLUGIN_LAUNCHER="$ZSH/plugins/emacs/emacsclient.sh" # set EDITOR if not already defined. @@ -18,15 +18,14 @@ if "$ZSH/tools/require_tool.sh" emacs 23 2>/dev/null ; then alias emacs="$EMACS_PLUGIN_LAUNCHER --no-wait" alias e=emacs + # open terminal emacsclient + alias te="$EMACS_PLUGIN_LAUNCHER -nw" # same than M-x eval but from outside Emacs. alias eeval="$EMACS_PLUGIN_LAUNCHER --eval" # create a new X frame alias eframe='emacsclient --alternate-editor "" --create-frame' - # to code all night long - alias emasc=emacs - alias emcas=emacs # Write to standard output the path to the file # opened in the current buffer. diff --git a/plugins/emacs/emacsclient.sh b/plugins/emacs/emacsclient.sh index d61ebb15b38d7..26b28d495b6a6 100755 --- a/plugins/emacs/emacsclient.sh +++ b/plugins/emacs/emacsclient.sh @@ -1,16 +1,16 @@ #!/bin/sh -function _emacsfun +_emacsfun() { - # get list of available X windows. - x=`emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null` + # get list of emacs frames. + frameslist=`emacsclient --alternate-editor '' --eval '(frame-list)' 2>/dev/null | egrep -o '(frame)+'` - if [ -z "$x" ] || [ "$x" = "nil" ] ;then - # Create one if there is no X window yet. - emacsclient --alternate-editor "" --create-frame "$@" - else + if [ "$(echo "$frameslist" | sed -n '$=')" -ge 2 ] ;then # prevent creating another X frame if there is at least one present. emacsclient --alternate-editor "" "$@" + else + # Create one if there is no X window yet. + emacsclient --alternate-editor "" --create-frame "$@" fi } @@ -18,7 +18,8 @@ function _emacsfun # adopted from https://github.com/davidshepherd7/emacs-read-stdin/blob/master/emacs-read-stdin.sh # If the second argument is - then write stdin to a tempfile and open the # tempfile. (first argument will be `--no-wait` passed in by the plugin.zsh) -if [[ $# -ge 2 ]] && [[ "$2" == - ]]; then +if [ "$#" -ge "2" -a "$2" = "-" ] +then tempfile="$(mktemp emacs-stdin-$USER.XXXXXXX --tmpdir)" cat - > "$tempfile" _emacsfun --no-wait $tempfile diff --git a/plugins/firewalld/firewalld.plugin.zsh b/plugins/firewalld/firewalld.plugin.zsh new file mode 100644 index 0000000000000..bfbf6f48fd581 --- /dev/null +++ b/plugins/firewalld/firewalld.plugin.zsh @@ -0,0 +1,17 @@ +alias fw="sudo firewall-cmd" +alias fwp="sudo firewall-cmd --permanent" +alias fwr="sudo firewall-cmd --reload" +alias fwrp="sudo firewall-cmd --runtime-to-permanent" + +function fwl () { + # converts output to zsh array () + # @f flag split on new line + zones=("${(@f)$(sudo firewall-cmd --get-active-zones | grep -v interfaces)}") + + for i in $zones; do + sudo firewall-cmd --zone $i --list-all + done + + echo 'Direct Rules:' + sudo firewall-cmd --direct --get-all-rules +} diff --git a/plugins/firewalld/readme.md b/plugins/firewalld/readme.md new file mode 100644 index 0000000000000..8b5bc74d45c76 --- /dev/null +++ b/plugins/firewalld/readme.md @@ -0,0 +1,22 @@ +# FirewallD Plugin + +This plugin adds some aliases and functions for FirewallD using the `firewalld-cmd` command. To use it, add firewalld to your plugins array. + +```zsh +plugins=(... firewalld) +``` + +## Aliases + +| Alias | Command | Description | +| :---- | :----------------------------------------- | :--------------------------- | +| fw | `sudo firewall-cmd` | Shorthand | +| fwr | `sudo firewall-cmd --reload` | Reload current configuration | +| fwp | `sudo firewall-cmd --permanent` | Create permanent rule | +| fwrp | `sudo firewall-cmd --runtime-to-permanent` | Save current configuration | + +## Functions + +| Function | Description | +| :------- | :--------------------------------------------------------- | +| fwl | Lists configuration from all active zones and direct rules | diff --git a/plugins/gb/README.md b/plugins/gb/README.md new file mode 100644 index 0000000000000..822c29aaa67be --- /dev/null +++ b/plugins/gb/README.md @@ -0,0 +1,21 @@ +# `gb` plugin + +> A project based build tool for the Go programming language. + +See https://getgb.io for the full `gb` documentation + +* * * * + +- Adds completion support for all `gb` commands. +- Also supports completion for the [`gb-vendor` plugin](https://godoc.org/github.com/constabulary/gb/cmd/gb-vendor). + +To use it, add `gb` to your plugins array: +```sh +plugins=(... gb) +``` + +## Caveats + +The `git` plugin defines an alias `gb` that usually conflicts with the `gb` program. +If you're having trouble with it, remove it by adding `unalias gb` at the end of your +zshrc file. diff --git a/plugins/gb/_gb b/plugins/gb/_gb new file mode 100644 index 0000000000000..8148adf160403 --- /dev/null +++ b/plugins/gb/_gb @@ -0,0 +1,111 @@ +#compdef gb +#autoload + +_gb () { + local ret=1 state + _arguments -C ':command:->command' '*::options:->options' && ret=0 + + case $state in + (command) + local -a subcommands + subcommands=( + "build:build a package" + "doc:show documentation for a package or symbol" + "env:print project environment variables" + "generate:generate Go files by processing source" + "help:displays the help" + "info:info returns information about this project" + "list:list the packages named by the importpaths" + "test:test packages" + "vendor:manage your vendored dependencies" + ) + _describe -t subcommands 'gb subcommands' subcommands && ret=0 + ;; + (options) + case $line[1] in + (build) + _arguments \ + -f'[ignore cached packages]' \ + -F'[do not cache packages]' \ + -q'[decreases verbosity]' \ + -P'[the number of build jobs to run in parallel]' \ + -R'[sets the base of the project root search path]' \ + -dotfile'[output a dot formatted file of the build steps]' \ + -ldflags'["flag list" arguments to pass to the linker]' \ + -gcflags'["arg list" arguments to pass to the compiler]' \ + -race'[enable data race detection]' \ + -tags'["tag list" additional build tags]' + ;; + (list) + _arguments \ + -f'[alternate format for the list, using the syntax of package template]' \ + -s'[read format template from STDIN]' \ + -json'[prints output in structured JSON format]' + ;; + (test) + _arguments \ + -v'[print output from test subprocess]' \ + -ldflags'["flag list" arguments to pass to the linker]' \ + -gcflags'["arg list" arguments to pass to the compiler]' \ + -race'[enable data race detection]' \ + -tags'["tag list" additional build tags]' + ;; + (vendor) + _gb-vendor + esac + ;; + esac + + return ret +} + +_gb-vendor () { + local curcontext="$curcontext" state line + _arguments -C ':command:->command' '*::options:->options' + + case $state in + (command) + local -a subcommands + subcommands=( + 'delete:deletes a local dependency' + 'fetch:fetch a remote dependency' + 'list:lists dependencies, one per line' + 'purge:remove all unreferenced dependencies' + 'restore:restore dependencies from the manifest' + 'update:update a local dependency' + ) + _describe -t subcommands 'gb vendor subcommands' subcommands && ret=0 + ;; + (options) + case $line[1] in + (delete) + _arguments \ + -all'[remove all dependencies]' + ;; + (fetch) + _arguments \ + -branch'[fetch from a particular branch]' \ + -no-recurse'[do not fetch recursively]' \ + -tag'[fetch the specified tag]' \ + -revision'[fetch the specific revision from the branch (if supplied)]' \ + -precaire'[allow the use of insecure protocols]' \ + ;; + (list) + _arguments \ + -f'[controls the template used for printing each manifest entry]' + ;; + (restore) + _arguments \ + -precaire'[allow the use of insecure protocols]' + ;; + (update) + _arguments \ + -all'[update all dependencies in the manifest or supply a given dependency]' \ + -precaire'[allow the use of insecure protocols]' + ;; + esac + ;; + esac +} + +_gb diff --git a/plugins/git-flow/README.md b/plugins/git-flow/README.md new file mode 100644 index 0000000000000..f37f418db4342 --- /dev/null +++ b/plugins/git-flow/README.md @@ -0,0 +1,31 @@ +# Git-Flow plugin + +This plugin adds completion and aliases for the `git-flow` command. More information +at https://github.com/nvie/gitflow. + +Enable git-flow plugin in your zshrc file: +``` +plugins=(... git-flow) +``` + +## Aliases + +More information about `git-flow` commands: +https://github.com/nvie/gitflow/wiki/Command-Line-Arguments + +| Alias | Command | Description | +|---------|---------------------------|----------------------------------------| +| `gfl` | `git flow` | Git-Flow command | +| `gfli` | `git flow init` | Initialize git-flow repository | +| `gcd` | `git checkout develop` | Check out develop branch | +| `gch` | `git checkout hotfix` | Check out hotfix branch | +| `gcr` | `git checkout release` | Check out release branch | +| `gflf` | `git flow feature` | List existing feature branches | +| `gflh` | `git flow hotfix` | List existing hotfix branches | +| `gflr` | `git flow release` | List existing release branches | +| `gflfs` | `git flow feature start` | Start a new feature: `gflfs ` | +| `gflhs` | `git flow hotfix start` | Start a new hotfix: `gflhs ` | +| `gflrs` | `git flow release start` | Start a new release: `gflrs ` | +| `gflff` | `git flow feature finish` | Finish feature: `gflff ` | +| `gflhf` | `git flow hotfix finish` | Finish hotfix: `gflhf ` | +| `gflrf` | `git flow release finish` | Finish release: `gflrf ` | diff --git a/plugins/git-flow/git-flow.plugin.zsh b/plugins/git-flow/git-flow.plugin.zsh index a8386cb19a115..bda050725e918 100644 --- a/plugins/git-flow/git-flow.plugin.zsh +++ b/plugins/git-flow/git-flow.plugin.zsh @@ -22,9 +22,19 @@ #Alias alias gfl='git flow' +alias gfli='git flow init' alias gcd='git checkout develop' alias gch='git checkout hotfix' alias gcr='git checkout release' +alias gflf='git flow feature' +alias gflh='git flow hotfix' +alias gflr='git flow release' +alias gflfs='git flow feature start' +alias gflhs='git flow hotfix start' +alias gflrs='git flow release start' +alias gflff='git flow feature finish' +alias gflhf='git flow hotfix finish' +alias gflrf='git flow release finish' _git-flow () { diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index eb7bc80345efd..25da035091cdd 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -46,7 +46,8 @@ alias gapa='git add --patch' alias gb='git branch' alias gba='git branch -a' -alias gbda='git branch --merged | command grep -vE "^(\*|\s*master\s*$)" | command xargs -n 1 git branch -d' +alias gbd='git branch -d' +alias gbda='git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d' alias gbl='git blame -b -w' alias gbnm='git branch --no-merged' alias gbr='git branch --remote' @@ -70,73 +71,90 @@ alias gcl='git clone --recursive' alias gclean='git clean -fd' alias gpristine='git reset --hard && git clean -dfx' alias gcm='git checkout master' +alias gcd='git checkout develop' alias gcmsg='git commit -m' alias gco='git checkout' alias gcount='git shortlog -sn' compdef gcount=git alias gcp='git cherry-pick' +alias gcpa='git cherry-pick --abort' +alias gcpc='git cherry-pick --continue' alias gcs='git commit -S' alias gd='git diff' alias gdca='git diff --cached' alias gdct='git describe --tags `git rev-list --tags --max-count=1`' alias gdt='git diff-tree --no-commit-id --name-only -r' +alias gdw='git diff --word-diff' + gdv() { git diff -w "$@" | view - } compdef _git gdv=git-diff -alias gdw='git diff --word-diff' alias gf='git fetch' alias gfa='git fetch --all --prune' -function gfg() { git ls-files | grep $@ } -compdef gfg=grep alias gfo='git fetch origin' +function gfg() { git ls-files | grep $@ } +compdef _grep gfg + alias gg='git gui citool' alias gga='git gui citool --amend' + ggf() { -[[ "$#" != 1 ]] && local b="$(git_current_branch)" -git push --force origin "${b:=$1}" + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git push --force origin "${b:=$1}" } compdef _git ggf=git-checkout + ggl() { -if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then -git pull origin "${*}" -else -[[ "$#" == 0 ]] && local b="$(git_current_branch)" -git pull origin "${b:=$1}" -fi + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then + git pull origin "${*}" + else + [[ "$#" == 0 ]] && local b="$(git_current_branch)" + git pull origin "${b:=$1}" + fi } compdef _git ggl=git-checkout -alias ggpull='git pull origin $(git_current_branch)' -compdef _git ggpull=git-checkout + ggp() { -if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then -git push origin "${*}" -else -[[ "$#" == 0 ]] && local b="$(git_current_branch)" -git push origin "${b:=$1}" -fi + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then + git push origin "${*}" + else + [[ "$#" == 0 ]] && local b="$(git_current_branch)" + git push origin "${b:=$1}" + fi } compdef _git ggp=git-checkout -alias ggpush='git push origin $(git_current_branch)' -compdef _git ggpush=git-checkout + ggpnp() { -if [[ "$#" == 0 ]]; then -ggl && ggp -else -ggl "${*}" && ggp "${*}" -fi + if [[ "$#" == 0 ]]; then + ggl && ggp + else + ggl "${*}" && ggp "${*}" + fi } compdef _git ggpnp=git-checkout -alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' + ggu() { -[[ "$#" != 1 ]] && local b="$(git_current_branch)" -git pull --rebase origin "${b:=$1}" + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git pull --rebase origin "${b:=$1}" } compdef _git ggu=git-checkout + alias ggpur='ggu' compdef _git ggpur=git-checkout +alias ggpull='git pull origin $(git_current_branch)' +compdef _git ggpull=git-checkout + +alias ggpush='git push origin $(git_current_branch)' +compdef _git ggpush=git-checkout + +alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' +alias gpsup='git push --set-upstream origin $(git_current_branch)' + +alias ghh='git help' + alias gignore='git update-index --assume-unchanged' alias gignored='git ls-files -v | grep "^[[:lower:]]"' alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk' @@ -144,7 +162,7 @@ compdef git-svn-dcommit-push=git alias gk='\gitk --all --branches' compdef _git gk='gitk' -alias gke='\gitk --all $(git log -g --pretty=format:%h)' +alias gke='\gitk --all $(git log -g --pretty=%h)' compdef _git gke='gitk' alias gl='git pull' @@ -154,8 +172,8 @@ alias glgg='git log --graph' alias glgga='git log --graph --decorate --all' alias glgm='git log --graph --max-count=10' alias glo='git log --oneline --decorate' -alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" -alias glola="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all" +alias glol="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" +alias glola="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all" alias glog='git log --oneline --decorate --graph' alias gloga='git log --oneline --decorate --graph --all' alias glp="_git_log_prettily" @@ -201,6 +219,7 @@ alias gss='git status -s' alias gst='git status' alias gsta='git stash save' alias gstaa='git stash apply' +alias gstc='git stash clear' alias gstd='git stash drop' alias gstl='git stash list' alias gstp='git stash pop' diff --git a/plugins/golang/golang.plugin.zsh b/plugins/golang/golang.plugin.zsh index 1ce3cea58e861..d9d4506908f16 100644 --- a/plugins/golang/golang.plugin.zsh +++ b/plugins/golang/golang.plugin.zsh @@ -179,5 +179,15 @@ __go_tool_complete() { compdef __go_tool_complete go -# aliases -alias gfa='go fmt . ./...' +# aliases: go<~> +alias gob='go build' +alias goc='go clean' +alias god='go doc' +alias gof='go fmt' +alias gofa='go fmt . ./...' +alias gog='go get' +alias goi='go install' +alias gol='go list' +alias gor='go run' +alias got='go test' +alias gov='go vet' diff --git a/plugins/gradle/_gradle b/plugins/gradle/_gradle new file mode 120000 index 0000000000000..80723f2fc07b3 --- /dev/null +++ b/plugins/gradle/_gradle @@ -0,0 +1 @@ +gradle.plugin.zsh \ No newline at end of file diff --git a/plugins/gradle/_gradlew b/plugins/gradle/_gradlew new file mode 120000 index 0000000000000..80723f2fc07b3 --- /dev/null +++ b/plugins/gradle/_gradlew @@ -0,0 +1 @@ +gradle.plugin.zsh \ No newline at end of file diff --git a/plugins/gradle/gradle.plugin.zsh b/plugins/gradle/gradle.plugin.zsh index a908eaeaa9ba3..b2015a351d062 100644 --- a/plugins/gradle/gradle.plugin.zsh +++ b/plugins/gradle/gradle.plugin.zsh @@ -60,6 +60,35 @@ _gradle_does_task_list_need_generating () { [[ ! -f .gradletasknamecache ]] || [[ build.gradle -nt .gradletasknamecache ]] } +############## +# Parse the tasks from `gradle(w) tasks --all` into .gradletasknamecache +# All lines in the output from gradle(w) that are between /^-+$/ and /^\s*$/ +# are considered to be tasks. If and when gradle adds support for listing tasks +# for programmatic parsing, this method can be deprecated. +############## +_gradle_parse_tasks () { + lines_might_be_tasks=false + task_name_buffer="" + while read -r line; do + if [[ $line =~ ^-+$ ]]; then + lines_might_be_tasks=true + # Empty buffer, because it contains items that are not tasks + task_name_buffer="" + elif [[ $line =~ ^\s*$ ]]; then + if [[ "$lines_might_be_tasks" = true ]]; then + # If a newline is found, send the buffer to .gradletasknamecache + while read -r task; do + echo $task | awk '/[a-zA-Z0-9:-]+/ {print $1}' + done <<< "$task_name_buffer" + # Empty buffer, because we are done with the tasks + task_name_buffer="" + fi + lines_might_be_tasks=false + elif [[ "$lines_might_be_tasks" = true ]]; then + task_name_buffer="${task_name_buffer}\n${line}" + fi + done <<< "$1" +} ############################################################################## # Discover the gradle tasks by running "gradle tasks --all" @@ -68,7 +97,7 @@ _gradle_tasks () { if [[ -f build.gradle ]]; then _gradle_arguments if _gradle_does_task_list_need_generating; then - gradle tasks --all | awk '/[a-zA-Z0-9:-]* - / {print $1}' > .gradletasknamecache + _gradle_parse_tasks "$(gradle tasks --all)" > .gradletasknamecache fi compadd -X "==== Gradle Tasks ====" $(cat .gradletasknamecache) fi @@ -78,7 +107,7 @@ _gradlew_tasks () { if [[ -f build.gradle ]]; then _gradle_arguments if _gradle_does_task_list_need_generating; then - ./gradlew tasks --all | awk '/[a-zA-Z0-9:-]* - / {print $1}' > .gradletasknamecache + _gradle_parse_tasks "$(./gradlew tasks --all)" > .gradletasknamecache fi compadd -X "==== Gradlew Tasks ====" $(cat .gradletasknamecache) fi diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh new file mode 100644 index 0000000000000..51ae142a2b352 --- /dev/null +++ b/plugins/kubectl/kubectl.plugin.zsh @@ -0,0 +1,7 @@ +# Autocompletion for kubectl, the command line interface for Kubernetes +# +# Author: https://github.com/pstadler + +if [ $commands[kubectl] ]; then + source <(kubectl completion zsh) +fi diff --git a/plugins/lein/lein.plugin.zsh b/plugins/lein/lein.plugin.zsh index 11c92979bb727..f4e50b4479453 100644 --- a/plugins/lein/lein.plugin.zsh +++ b/plugins/lein/lein.plugin.zsh @@ -33,6 +33,8 @@ function _lein_commands() { "version:print leiningen's version" ) _describe -t subcommands 'leiningen subcommands' subcommands && ret=0 + ;; + *) _files esac return ret diff --git a/plugins/mix/_mix b/plugins/mix/_mix index 3b3887b1fc4d1..57fdf808a7222 100644 --- a/plugins/mix/_mix +++ b/plugins/mix/_mix @@ -38,6 +38,15 @@ _1st_arguments=( 'local.hex:Install hex locally' 'local.rebar:Install rebar locally' 'new:Create a new Elixir project' + 'phoenix.digest:Digests and compress static files' + 'phoenix.gen.channel:Generates a Phoenix channel' + 'phoenix.gen.html:Generates controller, model and views for an HTML based resource' + 'phoenix.gen.json:Generates a controller and model for a JSON based resource' + 'phoenix.gen.model:Generates an Ecto model' + 'phoenix.gen.secret:Generates a secret' + 'phoenix.new:Create a new Phoenix application' + 'phoenix.routes:Prints all routes' + 'phoenix.server:Starts applications and their servers' 'run:Run the given file or expression' "test:Run a project's tests" '--help:Describe available tasks' @@ -49,7 +58,7 @@ __task_list () local expl declare -a tasks - tasks=(app.start archive archive.build archive.install archive.uninstall clean cmd compile compile.protocols deps deps.clean deps.compile deps.get deps.unlock deps.update do escript.build help hex hex.config hex.docs hex.info hex.key hex.outdated hex.owner hex.publish hex.search hex.user loadconfig local local.hex local.rebar new run test) + tasks=(app.start archive archive.build archive.install archive.uninstall clean cmd compile compile.protocols deps deps.clean deps.compile deps.get deps.unlock deps.update do escript.build help hex hex.config hex.docs hex.info hex.key hex.outdated hex.owner hex.publish hex.search hex.user loadconfig local local.hex local.rebar new phoenix.digest phoenix.gen.channel phoenix.gen.html phoenix.gen.json phoenix.gen.model phoenix.gen.secret phoenix.new phoenix.routes phoenix.server run test) _wanted tasks expl 'help' compadd $tasks } @@ -80,4 +89,3 @@ case $state in esac ;; esac - diff --git a/plugins/mvn/mvn.plugin.zsh b/plugins/mvn/mvn.plugin.zsh index 068963ac22a38..d290c98ec7b7b 100644 --- a/plugins/mvn/mvn.plugin.zsh +++ b/plugins/mvn/mvn.plugin.zsh @@ -172,7 +172,7 @@ function listMavenCompletions { gwt:browser gwt:clean gwt:compile gwt:compile-report gwt:css gwt:debug gwt:eclipse gwt:eclipseTest gwt:generateAsync gwt:help gwt:i18n gwt:mergewebxml gwt:resources gwt:run gwt:sdkInstall gwt:source-jar gwt:soyc gwt:test # options - -Dmaven.test.skip=true -DskipTests -Dmaven.surefire.debug -DenableCiProfile -Dpmd.skip=true -Dcheckstyle.skip=true -Dtycho.mode=maven -Dmaven.test.failure.ignore=true + -Dmaven.test.skip=true -DskipTests -DskipITs -Dmaven.surefire.debug -DenableCiProfile -Dpmd.skip=true -Dcheckstyle.skip=true -Dtycho.mode=maven -Dmaven.test.failure.ignore=true # arguments -am -amd -B -C -c -cpu -D -e -emp -ep -f -fae -ff -fn -gs -h -l -N -npr -npu -nsu -o -P -pl -q -rf -s -T -t -U -up -V -v -X @@ -181,6 +181,7 @@ function listMavenCompletions { archetype:generate generate-sources cobertura:cobertura -Dtest= `if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dtest=\1?' ; fi` + -Dit.test= `if [ -d ./src/test/java ] ; then find ./src/test/java -type f -name '*.java' | grep -v svn | sed 's?.*/\([^/]*\)\..*?-Dit.test=\1?' ; fi` ); } diff --git a/plugins/npm/npm.plugin.zsh b/plugins/npm/npm.plugin.zsh index 38e699ea0197e..43aedc36d502a 100644 --- a/plugins/npm/npm.plugin.zsh +++ b/plugins/npm/npm.plugin.zsh @@ -1,4 +1,15 @@ -eval "$(npm completion 2>/dev/null)" +(( $+commands[npm] )) && { + __NPM_COMPLETION_FILE="${ZSH_CACHE_DIR}/npm_completion" + + if [[ ! -f $__NPM_COMPLETION_FILE ]]; then + npm completion >! $__NPM_COMPLETION_FILE 2>/dev/null + [[ $? -ne 0 ]] && rm -f $__NPM_COMPLETION_FILE + fi + + [[ -f $__NPM_COMPLETION_FILE ]] && source $__NPM_COMPLETION_FILE + + unset __NPM_COMPLETION_FILE +} # Install dependencies globally alias npmg="npm i -g " @@ -20,3 +31,16 @@ alias npmE='PATH="$(npm bin)":"$PATH"' # Check which npm modules are outdated alias npmO="npm outdated" + +# Check package versions +alias npmV="npm -v" + +# List packages +alias npmL="npm list" + +# Run npm start +alias npmst="npm start" + +# Run npm test +alias npmt="npm test" + diff --git a/plugins/nvm/_nvm b/plugins/nvm/_nvm index a95c9e3753e5e..1414dcbb1782a 100644 --- a/plugins/nvm/_nvm +++ b/plugins/nvm/_nvm @@ -1,7 +1,7 @@ #compdef nvm #autoload -[[ -s ~/.nvm/nvm.sh ]] || return 0 +[[ -f "$NVM_DIR/nvm.sh" ]] || return 0 local -a _1st_arguments _1st_arguments=( diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 9709719fefb42..9dde3a266ae18 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -1,3 +1,5 @@ -# The addition 'nvm install' attempts in ~/.profile +# Set NVM_DIR if it isn't already defined +[[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.nvm" -[[ -s ~/.nvm/nvm.sh ]] && . ~/.nvm/nvm.sh +# Load nvm if it exists +[[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" diff --git a/plugins/osx/README.md b/plugins/osx/README.md index a06184a45b909..b77daecc5dc22 100644 --- a/plugins/osx/README.md +++ b/plugins/osx/README.md @@ -15,13 +15,19 @@ Original author: [Sorin Ionescu](https://github.com/sorin-ionescu) ## Commands -| Command | Description | -|:--------------|:-----------------------------------------------| -| `tab` | Open the current directory in a new tab | -| `ofd` | Open the current directory in a Finder window | -| `pfd` | Return the path of the frontmost Finder window | -| `pfs` | Return the current Finder selection | -| `cdf` | `cd` to the current Finder directory | -| `pushdf` | `pushd` to the current Finder directory | -| `quick-look` | Quick-Look a specified file | -| `man-preview` | Open a specified man page in Preview app | +| Command | Description | +| :-------------- | :----------------------------------------------- | +| `tab` | Open the current directory in a new tab | +| `split_tab` | Split the current terminal tab horizontally | +| `vsplit_tab` | Split the current terminal tab vertically | +| `ofd` | Open the current directory in a Finder window | +| `pfd` | Return the path of the frontmost Finder window | +| `pfs` | Return the current Finder selection | +| `cdf` | `cd` to the current Finder directory | +| `pushdf` | `pushd` to the current Finder directory | +| `quick-look` | Quick-Look a specified file | +| `man-preview` | Open a specified man page in Preview app | +| `showfiles` | Show hidden files | +| `hidefiles` | Hide the hidden files | +| `itunes` | Control iTunes. User `itunes -h` for usage details | +| `spotify` | Control Spotify and search by artist, album, track and etc.| diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index c66325cde46ce..aa6a256c11b53 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -44,7 +44,7 @@ EOF elif [[ "$the_app" == 'iTerm2' ]]; then osascript <"; + echo; + echo "Commands:"; + echo; + echo " play # Resumes playback where Spotify last left off."; + echo " play [song name] # Finds a song by name and plays it."; + echo " play album [album name] # Finds an album by name and plays it."; + echo " play artist [artist name] # Finds an artist by name and plays it."; + echo " play list [playlist name] # Finds a playlist by name and plays it."; + echo " pause # Pauses Spotify playback."; + echo " next # Skips to the next song in a playlist."; + echo " prev # Returns to the previous song in a playlist."; + echo " pos [time] # Jumps to a time (in secs) in the current song."; + echo " quit # Stops playback and quits Spotify."; + echo; + echo " vol up # Increases the volume by 10%."; + echo " vol down # Decreases the volume by 10%."; + echo " vol [amount] # Sets the volume to an amount between 0 and 100."; + echo " vol show # Shows the current Spotify volume."; + echo; + echo " status # Shows the current player status."; + echo " share # Copies the current song URL to the clipboard." + echo " info # Shows Full Information about song that is playing."; + echo; + echo " toggle shuffle # Toggles shuffle playback mode."; + echo " toggle repeat # Toggles repeat playback mode."; + } + + cecho(){ + bold=$(tput bold); + green=$(tput setaf 2); + reset=$(tput sgr0); + echo "$bold$green$1$reset"; + } + + showStatus () { + state=$(osascript -e 'tell application "Spotify" to player state as string'); + cecho "Spotify is currently $state."; + if [ "$state" = "playing" ]; then + artist=$(osascript -e 'tell application "Spotify" to artist of current track as string'); + album=$(osascript -e 'tell application "Spotify" to album of current track as string'); + track=$(osascript -e 'tell application "Spotify" to name of current track as string'); + duration=$(osascript -e 'tell application "Spotify" to duration of current track as string'); + duration=$(echo "scale=2; $duration / 60 / 1000" | bc); + position=$(osascript -e 'tell application "Spotify" to player position as string' | tr ',' '.'); + position=$(echo "scale=2; $position / 60" | bc | awk '{printf "%0.2f", $0}'); + + printf "$reset""Artist: %s\nAlbum: %s\nTrack: %s \nPosition: %s / %s" "$artist" "$album" "$track" "$position" "$duration"; + fi + } + + + + if [ $# = 0 ]; then + showHelp; + else + if [ "$(osascript -e 'application "Spotify" is running')" = "false" ]; then + osascript -e 'tell application "Spotify" to activate' + sleep 2 + fi + fi + + while [ $# -gt 0 ]; do + arg=$1; + + case $arg in + "play" ) + if [ $# != 1 ]; then + # There are additional arguments, so find out how many + array=( $@ ); + len=${#array[@]}; + SPOTIFY_SEARCH_API="https://api.spotify.com/v1/search" + SPOTIFY_PLAY_URI=""; + + searchAndPlay() { + type="$1" + Q="$2" + + cecho "Searching ${type}s for: $Q"; + + SPOTIFY_PLAY_URI=$( \ + curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=$type&limit=1&offset=0" -H "Accept: application/json" \ + | grep -E -o "spotify:$type:[a-zA-Z0-9]+" -m 1 + ) + } + + case $2 in + "list" ) + _args=${array[*]:2:$len}; + Q=$_args; + + cecho "Searching playlists for: $Q"; + + results=$( \ + curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" \ + | grep -E -o "spotify:user:[a-zA-Z0-9_]+:playlist:[a-zA-Z0-9]+" -m 10 \ + ) + + count=$( \ + echo "$results" | grep -c "spotify:user" \ + ) + + if [ "$count" -gt 0 ]; then + random=$(( RANDOM % count)); + + SPOTIFY_PLAY_URI=$( \ + echo "$results" | awk -v random="$random" '/spotify:user:[a-zA-Z0-9]+:playlist:[a-zA-Z0-9]+/{i++}i==random{print; exit}' \ + ) + fi;; + + "album" | "artist" | "track" ) + _args=${array[*]:2:$len}; + searchAndPlay "$2" "$_args";; + + * ) + _args=${array[*]:1:$len}; + searchAndPlay track "$_args";; + esac + + if [ "$SPOTIFY_PLAY_URI" != "" ]; then + cecho "Playing ($Q Search) -> Spotify URL: $SPOTIFY_PLAY_URI"; + + osascript -e "tell application \"Spotify\" to play track \"$SPOTIFY_PLAY_URI\""; + + else + cecho "No results when searching for $Q"; + fi + else + # play is the only param + cecho "Playing Spotify."; + osascript -e 'tell application "Spotify" to play'; + fi + break ;; + + "pause" ) + state=$(osascript -e 'tell application "Spotify" to player state as string'); + if [ "$state" = "playing" ]; then + cecho "Pausing Spotify."; + else + cecho "Playing Spotify."; + fi + + osascript -e 'tell application "Spotify" to playpause'; + break ;; + + "quit" ) + cecho "Quitting Spotify."; + osascript -e 'tell application "Spotify" to quit'; + exit 1 ;; + + "next" ) + cecho "Going to next track." ; + osascript -e 'tell application "Spotify" to next track'; + break ;; + + "prev" ) + cecho "Going to previous track."; + osascript -e 'tell application "Spotify" to previous track'; + break ;; + + "vol" ) + vol=$(osascript -e 'tell application "Spotify" to sound volume as integer'); + if [[ "$2" = "show" || "$2" = "" ]]; then + cecho "Current Spotify volume level is $vol."; + break ; + elif [ "$2" = "up" ]; then + if [ "$vol" -le 90 ]; then + newvol=$(( vol+10 )); + cecho "Increasing Spotify volume to $newvol."; + else + newvol=100; + cecho "Spotify volume level is at max."; + fi + elif [ "$2" = "down" ]; then + if [ "$vol" -ge 10 ]; then + newvol=$(( vol-10 )); + cecho "Reducing Spotify volume to $newvol."; + else + newvol=0; + cecho "Spotify volume level is at min."; + fi + elif [ "$2" -ge 0 ]; then + newvol=$2; + fi + + osascript -e "tell application \"Spotify\" to set sound volume to $newvol"; + break ;; + + "toggle" ) + if [ "$2" = "shuffle" ]; then + osascript -e 'tell application "Spotify" to set shuffling to not shuffling'; + curr=$(osascript -e 'tell application "Spotify" to shuffling'); + cecho "Spotify shuffling set to $curr"; + elif [ "$2" = "repeat" ]; then + osascript -e 'tell application "Spotify" to set repeating to not repeating'; + curr=$(osascript -e 'tell application "Spotify" to repeating'); + cecho "Spotify repeating set to $curr"; + fi + break ;; + + "pos" ) + cecho "Adjusting Spotify play position." + osascript -e "tell application \"Spotify\" to set player position to $2"; + break;; + + "status" ) + showStatus; + break ;; + + "info" ) + info=$(osascript -e 'tell application "Spotify" + set tM to round (duration of current track / 60) rounding down + set tS to duration of current track mod 60 + set pos to player position as text + set myTime to tM as text & "min " & tS as text & "s" + set nM to round (player position / 60) rounding down + set nS to round (player position mod 60) rounding down + set nowAt to nM as text & "min " & nS as text & "s" + set info to "" & "\nArtist: " & artist of current track + set info to info & "\nTrack: " & name of current track + set info to info & "\nAlbum Artist: " & album artist of current track + set info to info & "\nAlbum: " & album of current track + set info to info & "\nSeconds: " & duration of current track + set info to info & "\nSeconds played: " & pos + set info to info & "\nDuration: " & mytime + set info to info & "\nNow at: " & nowAt + set info to info & "\nPlayed Count: " & played count of current track + set info to info & "\nTrack Number: " & track number of current track + set info to info & "\nPopularity: " & popularity of current track + set info to info & "\nId: " & id of current track + set info to info & "\nSpotify URL: " & spotify url of current track + set info to info & "\nArtwork: " & artwork of current track + set info to info & "\nPlayer: " & player state + set info to info & "\nVolume: " & sound volume + set info to info & "\nShuffle: " & shuffling + set info to info & "\nRepeating: " & repeating + end tell + return info') + echo "$info"; + break ;; + + "share" ) + url=$(osascript -e 'tell application "Spotify" to spotify url of current track'); + remove='spotify:track:' + url=${url#$remove} + url="http://open.spotify.com/track/$url" + cecho "Share URL: $url"; + cecho -n "$url" | pbcopy + break;; + + -h|--help| *) + showHelp; + break ;; + esac + done +} + + +# Show/hide hidden files in the Finder +alias showfiles="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder" +alias hidefiles="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder" diff --git a/plugins/perms/README.md b/plugins/perms/README.md new file mode 100644 index 0000000000000..873c21d427069 --- /dev/null +++ b/plugins/perms/README.md @@ -0,0 +1,9 @@ +## Perms + +Plugin to handle some unix filesystem permissions quickly + +### Usage + +* `set755` recursively sets all directories located within the current working directory and sub directories to octal 755. +* `set644` recursively sets all files located within the current working directory and sub directories to octal 644. +* `fixperms` is a wrapper around `set755` and `set644` applied to a specified directory or the current directory otherwise. It also prompts prior to execution unlike the other two aliases. \ No newline at end of file diff --git a/plugins/perms/perms.plugin.zsh b/plugins/perms/perms.plugin.zsh new file mode 100644 index 0000000000000..7cdebab7f792e --- /dev/null +++ b/plugins/perms/perms.plugin.zsh @@ -0,0 +1,78 @@ +# Some useful commands for setting permissions. +# +# Rory Hardy [GneatGeek] +# Andrew Janke [apjanke] + +### Aliases + +# Set all files' permissions to 644 recursively in a directory +alias set644='find . -type f ! -perm 644 -print0 | xargs -0 chmod 644' + +# Set all directories' permissions to 755 recursively in a directory +alias set755='find . -type d ! -perm 755 -print0 | xargs -0 chmod 755' + +### Functions + +# fixperms - fix permissions on files and directories, with confirmation +# Returns 0 on success, nonzero if any errors occurred +fixperms () { + local opts confirm target exit_status chmod_opts use_slow_mode + zparseopts -E -D -a opts -help -slow v+=chmod_opts + if [[ $# > 1 || -n "${opts[(r)--help]}" ]]; then + cat < 1 )) + return $exit_status + fi + + if [[ $# == 0 ]]; then + target="." + else + target="$1" + fi + if [[ -n ${opts[(r)--slow]} ]]; then use_slow=true; else use_slow=false; fi + + # Because this requires confirmation, bail in noninteractive shells + if [[ ! -o interactive ]]; then + echo "fixperms: cannot run in noninteractive shell" + return 1 + fi + + echo "Fixing perms on $target?" + printf '%s' "Proceed? (y|n) " + read confirm + if [[ "$confirm" != y ]]; then + # User aborted + return 1 + fi + + # This xargs form is faster than -exec chmod {} \; but will encounter + # issues if the directories themselves have permissions such that you can't + # recurse in to them. If that happens, just rerun this a few times. + exit_status=0; + if [[ $use_slow == true ]]; then + # Process directories first so non-traversable ones are fixed as we go + find "$target" -type d ! -perm 755 -exec chmod $chmod_opts 755 {} \; + if [[ $? != 0 ]]; then exit_status=$?; fi + find "$target" -type f ! -perm 644 -exec chmod $chmod_opts 644 {} \; + if [[ $? != 0 ]]; then exit_status=$?; fi + else + find "$target" -type d ! -perm 755 -print0 | xargs -0 chmod $chmod_opts 755 + if [[ $? != 0 ]]; then exit_status=$?; fi + find "$target" -type f ! -perm 644 -print0 | xargs -0 chmod $chmod_opts 644 + if [[ $? != 0 ]]; then exit_status=$?; fi + fi + echo "Complete" + return $exit_status +} diff --git a/plugins/phing/phing.plugin.zsh b/plugins/phing/phing.plugin.zsh index 1f022047c1bbe..d5a2649bf22de 100644 --- a/plugins/phing/phing.plugin.zsh +++ b/plugins/phing/phing.plugin.zsh @@ -1,15 +1,6 @@ -_phing_does_target_list_need_generating () { - [ ! -f .phing_targets ] && return 0; - [ build.xml -nt .phing_targets ] && return 0; - return 1; -} - _phing () { if [ -f build.xml ]; then - if _phing_does_target_list_need_generating; then - phing -l|grep -v "\[property\]"|grep -v "Buildfile"|sed 1d|grep -v ":$" |grep -v "^\-*$"|awk '{print $1}' > .phing_targets - fi - compadd `cat .phing_targets` + compadd $(phing -l|grep -v "\[property\]"|grep -v "Buildfile"|sed 1d|grep -v ":$" |grep -v "^\-*$"|grep -v "Warning:"|awk '{print $1}') fi } diff --git a/plugins/pip/pip.plugin.zsh b/plugins/pip/pip.plugin.zsh index b5433ae9d6e25..d7236b02afb0f 100644 --- a/plugins/pip/pip.plugin.zsh +++ b/plugins/pip/pip.plugin.zsh @@ -76,3 +76,6 @@ zsh-pip-test-clean-packages() { echo "the djangopypi2 index is fine" fi } + +alias pip="noglob pip" # allows square brackets for pip command invocation + diff --git a/plugins/pj/README.md b/plugins/pj/README.md new file mode 100644 index 0000000000000..27e5638ec67ce --- /dev/null +++ b/plugins/pj/README.md @@ -0,0 +1,45 @@ +# pj + +The `pj` plugin (short for `Project Jump`) allows you to define several +folders where you store your projects, so that you can jump there directly +by just using the name of the project directory. + +Original idea and code by Jan De Poorter ([@DefV](https://github.com/DefV)) +Source: https://gist.github.com/pjaspers/368394#gistcomment-1016 + +## Usage + +1. Enable the `pj` plugin: + + ```zsh + plugins=(... pj) + ``` + +2. Set `$PROJECT_PATHS` in your ~/.zshrc: + + ```zsh + PROJECT_PATHS=(~/src ~/work ~/"dir with spaces") + ``` + +You can now use one of the following commands: + +##### `pj my-project`: + +`cd` to the directory named "my-project" found in one of the `$PROJECT_PATHS` +directories. If there are several directories named the same, the first one +to appear in `$PROJECT_PATHS` has preference. + +For example: +```zsh +PROJECT_PATHS=(~/code ~/work) +$ ls ~/code # ~/code/blog ~/code/react +$ ls ~/work # ~/work/blog ~/work/project +$ pj blog # <-- will cd to ~/code/blog +``` + +##### `pjo my-project` + +Open the project directory with your defined `$EDITOR`. This follows the same +directory rules as the `pj` command above. + +Note: `pjo` is an alias of `pj open`. diff --git a/plugins/pj/pj.plugin.zsh b/plugins/pj/pj.plugin.zsh index 1572e93634029..e36d49204f4e9 100644 --- a/plugins/pj/pj.plugin.zsh +++ b/plugins/pj/pj.plugin.zsh @@ -1,49 +1,37 @@ -#!/bin/zsh - -# -# Original idea by DefV (Jan De Poorter) -# Source: https://gist.github.com/pjaspers/368394#comment-1016 -# -# Usage: -# - Set `$PROJECT_PATHS` in your ~/.zshrc -# e.g.: PROJECT_PATHS=(~/src ~/work) -# - In ZSH you now can open a project directory with the command: `pj my-project` -# the plugin will locate the `my-project` directory in one of the $PROJECT_PATHS -# Also tab completion is supported. -# - `pjo my-project` will open the directory in $EDITOR -# - -function pj() { +alias pjo="pj open" + +pj () { + emulate -L zsh + cmd="cd" - file=$1 + project=$1 - if [[ "open" == "$file" ]] then + if [[ "open" == "$project" ]]; then shift - file=$* - cmd=(${(s: :)EDITOR}) + project=$* + cmd=${=EDITOR} else - file=$* + project=$* fi - for project in $PROJECT_PATHS; do - if [[ -d $project/$file ]] then - $cmd "$project/$file" - unset project # Unset project var + for basedir ($PROJECT_PATHS); do + if [[ -d "$basedir/$project" ]]; then + $cmd "$basedir/$project" return fi done - echo "No such project $1" + echo "No such project '${project}'." } -alias pjo="pj open" +_pj () { + emulate -L zsh -function _pj () { - # might be possible to improve this using glob, without the basename trick typeset -a projects - projects=($PROJECT_PATHS/*) - projects=$projects:t - _arguments "*:file:($projects)" -} + for basedir ($PROJECT_PATHS); do + projects+=(${basedir}/*(/N)) + done + compadd ${projects:t} +} compdef _pj pj diff --git a/plugins/rails/rails.plugin.zsh b/plugins/rails/rails.plugin.zsh index 5dfca49e9021f..c8974b5f432e4 100644 --- a/plugins/rails/rails.plugin.zsh +++ b/plugins/rails/rails.plugin.zsh @@ -36,6 +36,7 @@ alias -g RET='RAILS_ENV=test' # Rails aliases alias rc='rails console' +alias rcs='rails console --sandbox' alias rd='rails destroy' alias rdb='rails dbconsole' alias rg='rails generate' @@ -57,6 +58,7 @@ alias rdrs='rake db:reset' alias rdtc='rake db:test:clone' alias rdtp='rake db:test:prepare' alias rdmtc='rake db:migrate db:test:clone' +alias rdsl='rake db:schema:load' alias rlc='rake log:clear' alias rn='rake notes' alias rr='rake routes' diff --git a/plugins/rake-fast/README.md b/plugins/rake-fast/README.md index f56142f695326..1417befa15cef 100644 --- a/plugins/rake-fast/README.md +++ b/plugins/rake-fast/README.md @@ -2,22 +2,34 @@ Fast rake autocompletion plugin. -This script caches the output for later usage and significantly speeds it up. It generates a .rake_tasks cache file in parallel to the Rakefile. It also checks the file modification dates to see if it needs to regenerate the cache file. +This plugin caches the output for later usage and significantly speeds it up. +It generates a `.rake_tasks` cache file in parallel to the Rakefile. It also +checks the file modification time to see if it needs to regenerate the cache +file. -This is entirely based on [this pull request by Ullrich Schäfer](https://github.com/robb/.dotfiles/pull/10/), which is inspired by [this Ruby on Rails trick from 2006](http://weblog.rubyonrails.org/2006/3/9/fast-rake-task-completion-for-zsh/). +This is entirely based on [this pull request by Ullrich Schäfer](https://github.com/robb/.dotfiles/pull/10/), +which is inspired by [this Ruby on Rails trick from 2006](http://weblog.rubyonrails.org/2006/3/9/fast-rake-task-completion-for-zsh/). Think about that. 2006. +---------- + +Since August of 2016, it also checks if it's in a Rails project and looks at +rake files inside `lib/tasks` and their modification time to know if the +cache file needs to be regenerated. + ## Installation Just add the plugin to your `.zshrc`: -```bash -plugins=(foo bar rake-fast) +```zsh +plugins=(... rake-fast) ``` You might consider adding `.rake_tasks` to your [global .gitignore](https://help.github.com/articles/ignoring-files#global-gitignore) ## Usage -`rake`, then press tab +Type `rake`, then press tab. + +If you want to force the regeneration of the `.rake_tasks` file, run `rake_refresh`. diff --git a/plugins/rake-fast/rake-fast.plugin.zsh b/plugins/rake-fast/rake-fast.plugin.zsh index d305eb1f0516f..ca80d86e12964 100644 --- a/plugins/rake-fast/rake-fast.plugin.zsh +++ b/plugins/rake-fast/rake-fast.plugin.zsh @@ -1,14 +1,22 @@ -_rake_refresh () { - if [ -f .rake_tasks ]; then - rm .rake_tasks - fi - echo "Generating .rake_tasks..." > /dev/stderr - _rake_generate - cat .rake_tasks +_rake_does_task_list_need_generating () { + [[ ! -f .rake_tasks ]] || [[ Rakefile -nt .rake_tasks ]] || { _is_rails_app && _tasks_changed } } -_rake_does_task_list_need_generating () { - [[ ! -f .rake_tasks ]] || [[ Rakefile -nt .rake_tasks ]] +_is_rails_app () { + [[ -e "bin/rails" ]] || [[ -e "script/rails" ]] +} + +_tasks_changed () { + local -a files + files=(lib/tasks lib/tasks/**/*(N)) + + for file in $files; do + if [[ "$file" -nt .rake_tasks ]]; then + return 0 + fi + done + + return 1 } _rake_generate () { @@ -16,14 +24,20 @@ _rake_generate () { } _rake () { - if [ -f Rakefile ]; then + if [[ -f Rakefile ]]; then if _rake_does_task_list_need_generating; then - echo "\nGenerating .rake_tasks..." > /dev/stderr + echo "\nGenerating .rake_tasks..." >&2 _rake_generate fi - compadd `cat .rake_tasks` + compadd $(cat .rake_tasks) fi } - compdef _rake rake -alias rake_refresh='_rake_refresh' + +rake_refresh () { + [[ -f .rake_tasks ]] && rm -f .rake_tasks + + echo "Generating .rake_tasks..." >&2 + _rake_generate + cat .rake_tasks +} diff --git a/plugins/shrink-path/README.md b/plugins/shrink-path/README.md new file mode 100644 index 0000000000000..51fa8a0510c23 --- /dev/null +++ b/plugins/shrink-path/README.md @@ -0,0 +1,68 @@ +# A plugin to shrink directory paths for brevity and pretty-printing + + +## Examples + +For this directory tree: +``` + /home/ + me/ + foo/ + bar/ + quux/ + biz/ # The prefix b is ambiguous between bar and biz. +``` +here are the results of calling `shrink_path