Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Gaetan Semet 2016-08-10 17:38:10 +02:00
commit b3fb83b2d6
15 changed files with 312 additions and 154 deletions

View file

@ -3,11 +3,11 @@ function zsh_stats() {
} }
function uninstall_oh_my_zsh() { 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() { function upgrade_oh_my_zsh() {
env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh env ZSH=$ZSH sh $ZSH/tools/upgrade.sh
} }
function take() { function take() {

View file

@ -85,13 +85,19 @@ function git_current_branch() {
# Gets the number of commits ahead from remote # Gets the number of commits ahead from remote
function git_commits_ahead() { function git_commits_ahead() {
if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then if $(command git rev-parse --git-dir > /dev/null 2>&1); then
local COMMITS local COMMITS="$(git rev-list --count @{upstream}..HEAD)"
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" 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 2>&1); then
echo $(git rev-list --count HEAD..@{upstream})
fi
}
# Outputs if current branch is ahead of remote # Outputs if current branch is ahead of remote
function git_prompt_ahead() { function git_prompt_ahead() {
if [[ -n "$(command git rev-list origin/$(git_current_branch)..HEAD 2> /dev/null)" ]]; then if [[ -n "$(command git rev-list origin/$(git_current_branch)..HEAD 2> /dev/null)" ]]; then

View file

@ -1,6 +1,6 @@
# get the node.js version # get the node.js version
function nvm_prompt_info() { function nvm_prompt_info() {
[ -f "$HOME/.nvm/nvm.sh" ] || return [[ -f "$NVM_DIR/nvm.sh" ]] || return
local nvm_prompt local nvm_prompt
nvm_prompt=$(node -v 2>/dev/null) nvm_prompt=$(node -v 2>/dev/null)
[[ "${nvm_prompt}x" == "x" ]] && return [[ "${nvm_prompt}x" == "x" ]] && return

View file

@ -1,5 +1,4 @@
# Docker-compose plugin for oh my zsh # 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]

View file

@ -7,7 +7,7 @@
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# Version # Version
# ------- # -------
# 0.1.0 # 1.5.0
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# Authors # Authors
# ------- # -------
@ -19,58 +19,69 @@
# * @felixr docker zsh completion script : https://github.com/felixr/docker-zsh-completion # * @felixr docker zsh completion script : https://github.com/felixr/docker-zsh-completion
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# For compatibility reasons, Compose and therefore its completion supports several __docker-compose_q() {
# stack compositon files as listed here, in descending priority. docker-compose 2>/dev/null $compose_options "$@"
# 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
} }
# Extracts all service names from docker-compose.yml. # All services defined in docker-compose.yml
___docker-compose_all_services_in_compose_file() { __docker-compose_all_services_in_compose_file() {
local already_selected local already_selected
local -a services local -a services
already_selected=$(echo ${words[@]} | tr " " "|") 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" __docker-compose_q config --services \
| grep -Ev "^(${already_selected})$"
} }
# All services, even those without an existing container # All services, even those without an existing container
__docker-compose_services_all() { __docker-compose_services_all() {
services=$(___docker-compose_all_services_in_compose_file) [[ $PREFIX = -* ]] && return 1
_alternative "args:services:($services)" 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 # 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 already_selected
local -a buildable 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. # 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 # All services that are defined by a Dockerfile reference
__docker-compose_services_from_build() { __docker-compose_services_from_build() {
buildable=$(___docker-compose_services_with_key build) [[ $PREFIX = -* ]] && return 1
_alternative "args:buildable services:($buildable)" 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 # All services that are defined by an image
__docker-compose_services_from_image() { __docker-compose_services_from_image() {
pullable=$(___docker-compose_services_with_key image) [[ $PREFIX = -* ]] && return 1
_alternative "args:pullable services:($pullable)" integer ret=1
pullable=$(__docker-compose_services_with_key image)
_alternative "args:pullable services:($pullable)" && ret=0
return ret
} }
__docker-compose_get_services() { __docker-compose_get_services() {
local kind expl [[ $PREFIX = -* ]] && return 1
declare -a running stopped lines args services integer ret=1
local kind
declare -a running paused stopped lines args services
docker_status=$(docker ps > /dev/null 2>&1) docker_status=$(docker ps > /dev/null 2>&1)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -80,55 +91,69 @@ __docker-compose_get_services() {
kind=$1 kind=$1
shift shift
[[ $kind = (stopped|all) ]] && args=($args -a) [[ $kind =~ (stopped|all) ]] && args=($args -a)
lines=(${(f)"$(_call_program commands docker ps ${args})"}) lines=(${(f)"$(_call_program commands docker $docker_options ps $args)"})
services=(${(f)"$(_call_program commands docker-compose 2>/dev/null ${compose_file:+-f $compose_file} ${compose_project:+-p $compose_project} ps -q)"}) services=(${(f)"$(_call_program commands docker-compose 2>/dev/null $compose_options ps -q)"})
# Parse header line to find columns # Parse header line to find columns
local i=1 j=1 k header=${lines[1]} local i=1 j=1 k header=${lines[1]}
declare -A begin end declare -A begin end
while (( $j < ${#header} - 1 )) { while (( j < ${#header} - 1 )); do
i=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 1)) i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( $i + ${${header[$i,-1]}[(i) ]} - 1)) j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( $j + ${${header[$j,-1]}[(i)[^ ]]} - 2)) k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$(($j-1))]}]=$i begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$(($j-1))]}]=$k end[${header[$i,$((j-1))]}]=$k
} done
lines=(${lines[2,-1]}) lines=(${lines[2,-1]})
# Container ID # Container ID
local line s name local line s name
local -a names local -a names
for line in $lines; do 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]}%% *}}) names=(${(ps:,:)${${line[${begin[NAMES]},-1]}%% *}})
for name in $names; do for name in $names; do
s="${${name%_*}#*_}:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" s="${${name%_*}#*_}:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
s="$s, ${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}" 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 if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then
stopped=($stopped $s) stopped=($stopped $s)
else else
if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = *\(Paused\)* ]]; then
paused=($paused $s)
fi
running=($running $s) running=($running $s)
fi fi
done done
fi fi
done done
[[ $kind = (running|all) ]] && _describe -t services-running "running services" running [[ $kind =~ (running|all) ]] && _describe -t services-running "running services" running "$@" && ret=0
[[ $kind = (stopped|all) ]] && _describe -t services-stopped "stopped services" stopped [[ $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() { __docker-compose_stoppedservices() {
[[ $PREFIX = -* ]] && return 1
__docker-compose_get_services stopped "$@" __docker-compose_get_services stopped "$@"
} }
__docker-compose_runningservices() { __docker-compose_runningservices() {
[[ $PREFIX = -* ]] && return 1
__docker-compose_get_services running "$@" __docker-compose_get_services running "$@"
} }
__docker-compose_services() { __docker-compose_services() {
[[ $PREFIX = -* ]] && return 1
__docker-compose_get_services all "$@" __docker-compose_get_services all "$@"
} }
@ -151,104 +176,198 @@ __docker-compose_commands () {
local -a lines local -a lines
lines=(${(f)"$(_call_program commands docker-compose 2>&1)"}) lines=(${(f)"$(_call_program commands docker-compose 2>&1)"})
_docker_compose_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) _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 fi
_describe -t docker-compose-commands "docker-compose command" _docker_compose_subcommands _describe -t docker-compose-commands "docker-compose command" _docker_compose_subcommands
} }
__docker-compose_subcommand() { __docker-compose_subcommand() {
local -a _command_args 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 integer ret=1
case "$words[1]" in case "$words[1]" in
(build) (build)
_arguments \ _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 '*: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 "<project name>.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) (help)
_arguments ':subcommand:__docker-compose_commands' && ret=0 _arguments ':subcommand:__docker-compose_commands' && ret=0
;; ;;
(kill) (kill)
_arguments \ _arguments \
$opts_help \
'-s[SIGNAL to send to the container. Default signal is SIGKILL.]:signal:_signals' \ '-s[SIGNAL to send to the container. Default signal is SIGKILL.]:signal:_signals' \
'*:running services:__docker-compose_runningservices' && ret=0 '*:running services:__docker-compose_runningservices' && ret=0
;; ;;
(logs) (logs)
_arguments \ _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 '*:services:__docker-compose_services_all' && ret=0
;; ;;
(migrate-to-labels) (pause)
_arguments \ _arguments \
'(-):Recreate containers to add labels' && ret=0 $opts_help \
'*:running services:__docker-compose_runningservices' && ret=0
;; ;;
(port) (port)
_arguments \ _arguments \
'--protocol=-[tcp or udap (defaults to tcp)]:protocol:(tcp udp)' \ $opts_help \
'--index=-[index of the container if there are mutiple instances of a service (defaults to 1)]:index: ' \ '--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' \ '1:running services:__docker-compose_runningservices' \
'2:port:_ports' && ret=0 '2:port:_ports' && ret=0
;; ;;
(ps) (ps)
_arguments \ _arguments \
$opts_help \
'-q[Only display IDs]' \ '-q[Only display IDs]' \
'*:services:__docker-compose_services_all' && ret=0 '*:services:__docker-compose_services_all' && ret=0
;; ;;
(pull) (pull)
_arguments \ _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 '*: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) (rm)
_arguments \ _arguments \
$opts_help \
'(-f --force)'{-f,--force}"[Don't ask to confirm removal]" \ '(-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 '*:stopped services:__docker-compose_stoppedservices' && ret=0
;; ;;
(run) (run)
_arguments \ _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.]' \ '-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: ' \ '*-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' \ '--entrypoint[Overwrite the entrypoint of the image.]:entry point: ' \
"--no-deps[Don't start linked services.]" \ '--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.]' \ '--rm[Remove container after run. Ignored in detached mode.]' \
"--service-ports[Run command with the service's ports enabled and mapped to the host.]" \ "--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.]' \ '-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' \ '(-):services:__docker-compose_services' \
'(-):command: _command_names -e' \ '(-):command: _command_names -e' \
'*::arguments: _normal' && ret=0 '*::arguments: _normal' && ret=0
;; ;;
(scale) (scale)
_arguments '*:running services:__docker-compose_runningservices' && ret=0 _arguments \
$opts_help \
$opts_timeout \
'*:running services:__docker-compose_runningservices' && ret=0
;; ;;
(start) (start)
_arguments '*:stopped services:__docker-compose_stoppedservices' && ret=0 _arguments \
$opts_help \
'*:stopped services:__docker-compose_stoppedservices' && ret=0
;; ;;
(stop|restart) (stop|restart)
_arguments \ _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 '*:running services:__docker-compose_runningservices' && ret=0
;; ;;
(unpause)
_arguments \
$opts_help \
'*:paused services:__docker-compose_pausedservices' && ret=0
;;
(up) (up)
_arguments \ _arguments \
'--allow-insecure-ssl[Allow insecure connections to the docker registry]' \ $opts_help \
'-d[Detached mode: Run containers in the background, print new container names.]' \ '(--abort-on-container-exit)-d[Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit.]' \
'--no-color[Produce monochrome output.]' \ $opts_no_color \
"--no-deps[Don't start linked services.]" \ $opts_no_deps \
"--no-recreate[If containers already exist, don't recreate them.]" \ $opts_force_recreate \
"--no-build[Don't build an image, even if it's missing]" \ $opts_no_recreate \
'(-t --timeout)'{-t,--timeout}"[Specify a shutdown timeout in seconds. (default: 10)]:seconds: " \ $opts_no_build \
"--x-smart-recreate[Only recreate containers whose configuration or image needs to be updated. (EXPERIMENTAL)]" \ "(--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 '*:services:__docker-compose_services_all' && ret=0
;; ;;
(version) (version)
_arguments \ _arguments \
$opts_help \
"--short[Shows only Compose's version number.]" && ret=0 "--short[Shows only Compose's version number.]" && ret=0
;; ;;
(*) (*)
_message 'Unknown sub command' _message 'Unknown sub command' && ret=1
;;
esac esac
return ret return ret
@ -262,34 +381,62 @@ _docker-compose () {
return return
fi fi
local curcontext="$curcontext" state line ret=1 local curcontext="$curcontext" state line
integer ret=1
typeset -A opt_args typeset -A opt_args
_arguments -C \ _arguments -C \
'(- :)'{-h,--help}'[Get help]' \ '(- :)'{-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"' \ '(-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:' \ '(-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' \ '(-): :->command' \
'(-)*:: :->option-or-argument' && ret=0 '(-)*:: :->option-or-argument' && ret=0
local counter=1 local -a relevant_compose_flags relevant_docker_flags compose_options docker_options
#local compose_file compose_project
while [ $counter -lt ${#words[@]} ]; do relevant_compose_flags=(
case "${words[$counter]}" in "--file" "-f"
-f|--file) "--host" "-H"
(( counter++ )) "--project-name" "-p"
compose_file="${words[$counter]}" "--tls"
;; "--tlscacert"
-p|--project-name) "--tlscert"
(( counter++ )) "--tlskey"
compose_project="${words[$counter]}" "--tlsverify"
;; "--skip-hostname-check"
*) )
;;
esac relevant_docker_flags=(
(( counter++ )) "--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 done
case $state in case $state in

View file

@ -10,7 +10,7 @@
# - Configuration changes made at runtime are applied to all frames. # - 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" export EMACS_PLUGIN_LAUNCHER="$ZSH/plugins/emacs/emacsclient.sh"
# set EDITOR if not already defined. # 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 emacs="$EMACS_PLUGIN_LAUNCHER --no-wait"
alias e=emacs alias e=emacs
# open terminal emacsclient
alias te="$EMACS_PLUGIN_LAUNCHER -nw"
# same than M-x eval but from outside Emacs. # same than M-x eval but from outside Emacs.
alias eeval="$EMACS_PLUGIN_LAUNCHER --eval" alias eeval="$EMACS_PLUGIN_LAUNCHER --eval"
# create a new X frame # create a new X frame
alias eframe='emacsclient --alternate-editor "" --create-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 # Write to standard output the path to the file
# opened in the current buffer. # opened in the current buffer.

View file

@ -2,15 +2,15 @@
_emacsfun() _emacsfun()
{ {
# get list of available X windows. # get list of emacs frames.
x=`emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null` frameslist=`emacsclient --alternate-editor '' --eval '(frame-list)' 2>/dev/null | egrep -o '(frame)+'`
if [ -z "$x" ] || [ "$x" = "nil" ] ;then if [ "$(echo "$frameslist" | sed -n '$=')" -ge 2 ] ;then
# Create one if there is no X window yet.
emacsclient --alternate-editor "" --create-frame "$@"
else
# prevent creating another X frame if there is at least one present. # prevent creating another X frame if there is at least one present.
emacsclient --alternate-editor "" "$@" emacsclient --alternate-editor "" "$@"
else
# Create one if there is no X window yet.
emacsclient --alternate-editor "" --create-frame "$@"
fi fi
} }

View file

@ -46,7 +46,7 @@ alias gapa='git add --patch'
alias gb='git branch' alias gb='git branch'
alias gba='git branch -a' alias gba='git branch -a'
alias gbda='git branch --merged | command grep -vE "^(\*|\s*master\s*$)" | command xargs -n 1 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 gbl='git blame -b -w'
alias gbnm='git branch --no-merged' alias gbnm='git branch --no-merged'
alias gbr='git branch --remote' alias gbr='git branch --remote'
@ -81,23 +81,27 @@ alias gd='git diff'
alias gdca='git diff --cached' alias gdca='git diff --cached'
alias gdct='git describe --tags `git rev-list --tags --max-count=1`' alias gdct='git describe --tags `git rev-list --tags --max-count=1`'
alias gdt='git diff-tree --no-commit-id --name-only -r' alias gdt='git diff-tree --no-commit-id --name-only -r'
alias gdw='git diff --word-diff'
gdv() { git diff -w "$@" | view - } gdv() { git diff -w "$@" | view - }
compdef _git gdv=git-diff compdef _git gdv=git-diff
alias gdw='git diff --word-diff'
alias gf='git fetch' alias gf='git fetch'
alias gfa='git fetch --all --prune' alias gfa='git fetch --all --prune'
alias gfo='git fetch origin'
function gfg() { git ls-files | grep $@ } function gfg() { git ls-files | grep $@ }
compdef _grep gfg compdef _grep gfg
alias gfo='git fetch origin'
alias gg='git gui citool' alias gg='git gui citool'
alias gga='git gui citool --amend' alias gga='git gui citool --amend'
ggf() { ggf() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)" [[ "$#" != 1 ]] && local b="$(git_current_branch)"
git push --force origin "${b:=$1}" git push --force origin "${b:=$1}"
} }
compdef _git ggf=git-checkout compdef _git ggf=git-checkout
ggl() { ggl() {
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git pull origin "${*}" git pull origin "${*}"
@ -107,8 +111,7 @@ git pull origin "${b:=$1}"
fi fi
} }
compdef _git ggl=git-checkout compdef _git ggl=git-checkout
alias ggpull='git pull origin $(git_current_branch)'
compdef _git ggpull=git-checkout
ggp() { ggp() {
if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
git push origin "${*}" git push origin "${*}"
@ -118,8 +121,7 @@ git push origin "${b:=$1}"
fi fi
} }
compdef _git ggp=git-checkout compdef _git ggp=git-checkout
alias ggpush='git push origin $(git_current_branch)'
compdef _git ggpush=git-checkout
ggpnp() { ggpnp() {
if [[ "$#" == 0 ]]; then if [[ "$#" == 0 ]]; then
ggl && ggp ggl && ggp
@ -128,15 +130,24 @@ ggl "${*}" && ggp "${*}"
fi fi
} }
compdef _git ggpnp=git-checkout compdef _git ggpnp=git-checkout
alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
ggu() { ggu() {
[[ "$#" != 1 ]] && local b="$(git_current_branch)" [[ "$#" != 1 ]] && local b="$(git_current_branch)"
git pull --rebase origin "${b:=$1}" git pull --rebase origin "${b:=$1}"
} }
compdef _git ggu=git-checkout compdef _git ggu=git-checkout
alias ggpur='ggu' alias ggpur='ggu'
compdef _git ggpur=git-checkout 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 gignore='git update-index --assume-unchanged' alias gignore='git update-index --assume-unchanged'
alias gignored='git ls-files -v | grep "^[[:lower:]]"' alias gignored='git ls-files -v | grep "^[[:lower:]]"'
alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk' alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'

View file

@ -1,7 +1,7 @@
#compdef nvm #compdef nvm
#autoload #autoload
[[ -s ~/.nvm/nvm.sh ]] || return 0 [[ -f "$NVM_DIR/nvm.sh" ]] || return 0
local -a _1st_arguments local -a _1st_arguments
_1st_arguments=( _1st_arguments=(

View file

@ -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"

View file

@ -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 () { _phing () {
if [ -f build.xml ]; then if [ -f build.xml ]; then
if _phing_does_target_list_need_generating; then compadd $(phing -l|grep -v "\[property\]"|grep -v "Buildfile"|sed 1d|grep -v ":$" |grep -v "^\-*$"|grep -v "Warning:"|awk '{print $1}')
phing -l|grep -v "\[property\]"|grep -v "Buildfile"|sed 1d|grep -v ":$" |grep -v "^\-*$"|awk '{print $1}' > .phing_targets
fi
compadd `cat .phing_targets`
fi fi
} }

View file

@ -10,6 +10,7 @@ function web_search() {
bing "https://www.bing.com/search?q=" bing "https://www.bing.com/search?q="
yahoo "https://search.yahoo.com/search?p=" yahoo "https://search.yahoo.com/search?p="
duckduckgo "https://www.duckduckgo.com/?q=" duckduckgo "https://www.duckduckgo.com/?q="
startpage "https://www.startpage.com/do/search?q="
yandex "https://yandex.ru/yandsearch?text=" yandex "https://yandex.ru/yandsearch?text="
github "https://github.com/search?q=" github "https://github.com/search?q="
baidu "https://www.baidu.com/s?wd=" baidu "https://www.baidu.com/s?wd="
@ -41,6 +42,7 @@ alias bing='web_search bing'
alias google='web_search google' alias google='web_search google'
alias yahoo='web_search yahoo' alias yahoo='web_search yahoo'
alias ddg='web_search duckduckgo' alias ddg='web_search duckduckgo'
alias sp='web_search startpage'
alias yandex='web_search yandex' alias yandex='web_search yandex'
alias github='web_search github' alias github='web_search github'
alias baidu='web_search baidu' alias baidu='web_search baidu'

View file

@ -128,6 +128,7 @@ prompt_git() {
} }
prompt_hg() { prompt_hg() {
(( $+commands[hg] )) || return
local rev status local rev status
if $(hg id >/dev/null 2>&1); then if $(hg id >/dev/null 2>&1); then
if $(hg prompt >/dev/null 2>&1); then if $(hg prompt >/dev/null 2>&1); then

View file

@ -13,7 +13,7 @@ GIT_DIRTY_COLOR=$FG[133]
GIT_CLEAN_COLOR=$FG[118] GIT_CLEAN_COLOR=$FG[118]
GIT_PROMPT_INFO=$FG[012] GIT_PROMPT_INFO=$FG[012]
PROMPT='%{$PROMPT_SUCCESS_COLOR%}%~%{$reset_color%} %{$GIT_PROMPT_INFO%}$(git_prompt_info)%{$GIT_DIRTY_COLOR%}$(git_prompt_status) %{$reset_color%}%{$PROMPT_PROMPT%}ᐅ%{$reset_color%} ' PROMPT='%{$PROMPT_SUCCESS_COLOR%}%~%{$reset_color%} %{$GIT_PROMPT_INFO%}$(git_prompt_info) $(virtualenv_prompt_info)%{$GIT_DIRTY_COLOR%}$(git_prompt_status) %{$reset_color%}%{$PROMPT_PROMPT%}ᐅ%{$reset_color%} '
#RPS1="${return_code}" #RPS1="${return_code}"

View file

@ -11,7 +11,7 @@ function _update_zsh_update() {
} }
function _upgrade_zsh() { function _upgrade_zsh() {
env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh env ZSH=$ZSH sh $ZSH/tools/upgrade.sh
# update the zsh file # update the zsh file
_update_zsh_update _update_zsh_update
} }