mirror of https://github.com/docker/cli.git
Several cosmetic improvements in zsh completion
Signed-off-by: Steve Durrheimer <s.durrheimer@gmail.com>
This commit is contained in:
parent
31c530fd42
commit
66c1b06bc4
|
@ -45,18 +45,18 @@ __docker_get_containers() {
|
||||||
shift
|
shift
|
||||||
[[ $kind = (stopped|all) ]] && args=($args -a)
|
[[ $kind = (stopped|all) ]] && args=($args -a)
|
||||||
|
|
||||||
lines=(${(f)"$(_call_program commands docker $docker_options ps ${args})"})
|
lines=(${(f)"$(_call_program commands docker $docker_options ps $args)"})
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -65,7 +65,7 @@ __docker_get_containers() {
|
||||||
for line in $lines; do
|
for line in $lines; do
|
||||||
s="${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}"
|
s="${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}"
|
||||||
s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
|
s="$s:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}"
|
||||||
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
|
||||||
|
@ -80,7 +80,7 @@ __docker_get_containers() {
|
||||||
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[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
|
||||||
|
@ -101,11 +101,11 @@ __docker_runningcontainers() {
|
||||||
__docker_get_containers running "$@"
|
__docker_get_containers running "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
__docker_containers () {
|
__docker_containers() {
|
||||||
__docker_get_containers all "$@"
|
__docker_get_containers all "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
__docker_images () {
|
__docker_images() {
|
||||||
local expl
|
local expl
|
||||||
declare -a images
|
declare -a images
|
||||||
images=(${${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/ ##/\\:}%% *})
|
images=(${${${${(f)"$(_call_program commands docker $docker_options images)"}[2,-1]}/ ##/\\:}%% *})
|
||||||
|
@ -151,21 +151,20 @@ __docker_search() {
|
||||||
_wanted dockersearch expl 'available images' compadd -a result
|
_wanted dockersearch expl 'available images' compadd -a result
|
||||||
}
|
}
|
||||||
|
|
||||||
__docker_caching_policy()
|
__docker_caching_policy() {
|
||||||
{
|
oldp=( "$1(Nmh+1)" ) # 1 hour
|
||||||
oldp=( "$1"(Nmh+1) ) # 1 hour
|
(( ${#oldp} ))
|
||||||
(( $#oldp ))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__docker_repositories () {
|
__docker_repositories() {
|
||||||
local expl
|
local expl
|
||||||
declare -a repos
|
declare -a repos
|
||||||
repos=(${${${(f)"$(_call_program commands docker $docker_options images)"}%% *}[2,-1]})
|
repos=(${${${(f)"$(_call_program commands docker $docker_options images)"}%% *}[2,-1]})
|
||||||
_describe -t docker-repos "repositories" repos "$@"
|
_describe -t docker-repos "repositories" repos "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
__docker_commands () {
|
__docker_commands() {
|
||||||
# local -a _docker_subcommands
|
# local -a _docker_subcommands
|
||||||
local cache_policy
|
local cache_policy
|
||||||
|
|
||||||
|
@ -186,7 +185,7 @@ __docker_commands () {
|
||||||
_describe -t docker-commands "docker command" _docker_subcommands
|
_describe -t docker-commands "docker command" _docker_subcommands
|
||||||
}
|
}
|
||||||
|
|
||||||
__docker_subcommand () {
|
__docker_subcommand() {
|
||||||
local -a _command_args
|
local -a _command_args
|
||||||
case "$words[1]" in
|
case "$words[1]" in
|
||||||
(attach)
|
(attach)
|
||||||
|
@ -577,9 +576,9 @@ __docker_subcommand () {
|
||||||
;;
|
;;
|
||||||
(tag)
|
(tag)
|
||||||
_arguments \
|
_arguments \
|
||||||
'(-f --force)'{-f,--force}'[force]'\
|
'(-f --force)'{-f,--force}'[force]' \
|
||||||
'(- :)--help[Print usage]' \
|
'(- :)--help[Print usage]' \
|
||||||
':image:__docker_images'\
|
':image:__docker_images' \
|
||||||
':repository:__docker_repositories_with_tags' && ret=0
|
':repository:__docker_repositories_with_tags' && ret=0
|
||||||
;;
|
;;
|
||||||
(top)
|
(top)
|
||||||
|
@ -608,7 +607,7 @@ __docker_subcommand () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_docker () {
|
_docker() {
|
||||||
# Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`.
|
# 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`.
|
# Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`.
|
||||||
if [[ $service != docker ]]; then
|
if [[ $service != docker ]]; then
|
||||||
|
@ -616,8 +615,9 @@ _docker () {
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local curcontext="$curcontext" state line ret=1
|
local curcontext="$curcontext" state line
|
||||||
typeset -A opt_args
|
typeset -A opt_args
|
||||||
|
integer ret=1
|
||||||
|
|
||||||
_arguments -C \
|
_arguments -C \
|
||||||
'--api-cors-header=-[Set CORS headers in the remote API]:CORS headers: ' \
|
'--api-cors-header=-[Set CORS headers in the remote API]:CORS headers: ' \
|
||||||
|
@ -637,7 +637,7 @@ _docker () {
|
||||||
'--fixed-cidr-v6=-[IPv6 subnet for fixed IPs]:IPv6 subnet: ' \
|
'--fixed-cidr-v6=-[IPv6 subnet for fixed IPs]:IPv6 subnet: ' \
|
||||||
'(-G --group)'{-G,--group=-}'[Group for the unix socket (default: docker)]:group:_groups' \
|
'(-G --group)'{-G,--group=-}'[Group for the unix socket (default: docker)]:group:_groups' \
|
||||||
'(-g --graph)'{-g,--graph=-}'[Root of the Docker runtime (default: /var/lib/docker)]:PATH:_directories' \
|
'(-g --graph)'{-g,--graph=-}'[Root of the Docker runtime (default: /var/lib/docker)]:PATH:_directories' \
|
||||||
'(-H --host)'{-H,--host=-}'[tcp://host:port to bind/connect to]:socket: ' \
|
'(-H --host)'{-H,--host=-}'[tcp://host:port to bind/connect to]:host: ' \
|
||||||
'(-h --help)'{-h,--help}'[Print usage]' \
|
'(-h --help)'{-h,--help}'[Print usage]' \
|
||||||
'--icc[Enable inter-container communication]' \
|
'--icc[Enable inter-container communication]' \
|
||||||
'*--insecure-registry=-[Enable insecure registry communication]:registry: ' \
|
'*--insecure-registry=-[Enable insecure registry communication]:registry: ' \
|
||||||
|
@ -666,10 +666,6 @@ _docker () {
|
||||||
'(-): :->command' \
|
'(-): :->command' \
|
||||||
'(-)*:: :->option-or-argument' && ret=0
|
'(-)*:: :->option-or-argument' && ret=0
|
||||||
|
|
||||||
if (( CURRENT == 1 )); then
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
local counter=1
|
local counter=1
|
||||||
while [ $counter -lt ${#words} ]; do
|
while [ $counter -lt ${#words} ]; do
|
||||||
case "${words[$counter]}" in
|
case "${words[$counter]}" in
|
||||||
|
|
Loading…
Reference in New Issue