Another round of more bash-like syntax.

Signed-off-by: Edênis Freindorfer Azevedo <edenisfa@gmail.com>
This commit is contained in:
Edênis Freindorfer Azevedo 2021-08-31 08:19:48 -03:00
parent b73b4ec7fb
commit f73bcca529
No known key found for this signature in database
GPG Key ID: F7F1907D677FB8C9

View File

@ -1,6 +1,6 @@
# lxc-* commands completion # lxc-* commands completion
_lxc_names() { __lxc_names() {
declare -a names declare -a names
case ${words[0]} in case ${words[0]} in
lxc-attach | lxc-cgroup | lxc-checkpoint | lxc-console | lxc-device | lxc-freeze | lxc-stop ) lxc-attach | lxc-cgroup | lxc-checkpoint | lxc-console | lxc-device | lxc-freeze | lxc-stop )
@ -35,7 +35,7 @@ _lxc_names() {
done done
} }
_lxc_append_name() { __lxc_append_name() {
mapfile -t names < <(command lxc-ls -1) mapfile -t names < <(command lxc-ls -1)
local -r shortoptnamexp="^-[0-9A-Za-mo-z]*n[0-9A-Za-mo-z]*$" local -r shortoptnamexp="^-[0-9A-Za-mo-z]*n[0-9A-Za-mo-z]*$"
local parsed local parsed
@ -52,10 +52,10 @@ _lxc_append_name() {
[[ "${parsed}" == "${name}" ]] && return [[ "${parsed}" == "${name}" ]] && return
done done
done done
_lxc_names __lxc_names
} }
_lxc_get_snapshots() { __lxc_get_snapshots() {
mapfile -t names < <(command lxc-ls -1) mapfile -t names < <(command lxc-ls -1)
local -r shortoptnamexp="^-[0-9A-Za-mo-z]*n[0-9A-Za-mo-z]*$" local -r shortoptnamexp="^-[0-9A-Za-mo-z]*n[0-9A-Za-mo-z]*$"
local container local container
@ -93,7 +93,7 @@ _lxc_get_snapshots() {
fi fi
} }
_lxc_common_opt() { __lxc_common_opt() {
# End of options. # End of options.
if [[ "${words[*]}" =~ ' -- ' ]]; then if [[ "${words[*]}" =~ ' -- ' ]]; then
return 1 return 1
@ -150,7 +150,7 @@ __lxc_array_has_duplicates() {
declare -A unique declare -A unique
for word in "${@}"; do for word in "${@}"; do
if [[ -z "${unique[${word}]}" ]]; then if [[ -z "${unique[${word}]}" ]]; then
unique[${word}]="${word}" unique["${word}"]="${word}"
else else
return 0 return 0
fi fi
@ -244,11 +244,11 @@ _lxc_attach() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile | -f ) --rcfile | -f )
@ -304,8 +304,8 @@ _lxc_attach() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_attach lxc-attach complete -F _lxc_attach lxc-attach
__lxc_groups() { __lxc_groups() {
@ -323,7 +323,7 @@ _lxc_autostart() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--reboot | -r | --shutdown | -s | --kill | -k | --list | -L | --all | -a | --ignore-auto | -A ) --reboot | -r | --shutdown | -s | --kill | -k | --list | -L | --all | -a | --ignore-auto | -A )
@ -347,7 +347,7 @@ _lxc_autostart() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
} } &&
complete -F _lxc_autostart lxc-autostart complete -F _lxc_autostart lxc-autostart
_lxc_cgroup() { _lxc_cgroup() {
@ -355,11 +355,11 @@ _lxc_cgroup() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -375,8 +375,8 @@ _lxc_cgroup() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_cgroup lxc-cgroup complete -F _lxc_cgroup lxc-cgroup
_lxc_checkpoint() { _lxc_checkpoint() {
@ -384,11 +384,11 @@ _lxc_checkpoint() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -415,8 +415,8 @@ _lxc_checkpoint() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_checkpoint lxc-checkpoint complete -F _lxc_checkpoint lxc-checkpoint
_lxc_config() { _lxc_config() {
@ -431,7 +431,7 @@ _lxc_config() {
return return
fi fi
COMPREPLY=( $( compgen -W "$( command lxc-config -l )" -- "${cur}" ) ) COMPREPLY=( $( compgen -W "$( command lxc-config -l )" -- "${cur}" ) )
} } &&
complete -F _lxc_config lxc-config complete -F _lxc_config lxc-config
_lxc_console() { _lxc_console() {
@ -439,11 +439,11 @@ _lxc_console() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -468,8 +468,8 @@ _lxc_console() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_console lxc-console complete -F _lxc_console lxc-console
__lxc_backing_stores() { __lxc_backing_stores() {
@ -481,11 +481,11 @@ _lxc_copy() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -519,8 +519,8 @@ _lxc_copy() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_copy lxc-copy complete -F _lxc_copy lxc-copy
__lxc_templates() { __lxc_templates() {
@ -532,11 +532,11 @@ _lxc_create() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -564,7 +564,7 @@ _lxc_create() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
} } &&
complete -F _lxc_create lxc-create complete -F _lxc_create lxc-create
_lxc_destroy() { _lxc_destroy() {
@ -572,11 +572,11 @@ _lxc_destroy() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -595,8 +595,8 @@ _lxc_destroy() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_destroy lxc-destroy complete -F _lxc_destroy lxc-destroy
_lxc_device() { _lxc_device() {
@ -609,7 +609,7 @@ _lxc_device() {
return return
;; ;;
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
add ) add )
@ -626,8 +626,8 @@ _lxc_device() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_device lxc-device complete -F _lxc_device lxc-device
_lxc_execute() { _lxc_execute() {
@ -635,11 +635,11 @@ _lxc_execute() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile | -f ) --rcfile | -f )
@ -672,8 +672,8 @@ _lxc_execute() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_execute lxc-execute complete -F _lxc_execute lxc-execute
_lxc_freeze() { _lxc_freeze() {
@ -681,11 +681,11 @@ _lxc_freeze() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile | -f ) --rcfile | -f )
@ -701,8 +701,8 @@ _lxc_freeze() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_freeze lxc-freeze complete -F _lxc_freeze lxc-freeze
_lxc_info() { _lxc_info() {
@ -710,11 +710,11 @@ _lxc_info() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -739,15 +739,15 @@ _lxc_info() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_info lxc-info complete -F _lxc_info lxc-info
_lxc_ls() { _lxc_ls() {
local cur prev words cword split local cur prev words cword split
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--line | -1 | --fancy | -f | --active | --frozen | --running | --stopped | --defined ) --line | -1 | --fancy | -f | --active | --frozen | --running | --stopped | --defined )
@ -779,18 +779,18 @@ _lxc_ls() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
} } &&
complete -F _lxc_ls lxc-ls complete -F _lxc_ls lxc-ls
_lxc_monitor() { _lxc_monitor() {
local cur prev words cword split local cur prev words cword split
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--quit | -Q ) --quit | -Q )
@ -805,19 +805,19 @@ _lxc_monitor() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_monitor lxc-monitor complete -F _lxc_monitor lxc-monitor
_lxc_snapshot() { _lxc_snapshot() {
local cur prev words cword split local cur prev words cword split
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -829,14 +829,14 @@ _lxc_snapshot() {
return return
;; ;;
--destroy | -d ) --destroy | -d )
COMPREPLY=( $( compgen -W 'ALL $( _lxc_get_snapshots )' -- "${cur}" ) ) COMPREPLY=( $( compgen -W 'ALL $( __lxc_get_snapshots )' -- "${cur}" ) )
return return
;; ;;
--list | -L | --showcomments | -C ) --list | -L | --showcomments | -C )
# Only flags. # Only flags.
;; ;;
--restore | -r ) --restore | -r )
COMPREPLY=( $( compgen -W '$( _lxc_get_snapshots )' -- "${cur}" ) ) COMPREPLY=( $( compgen -W '$( __lxc_get_snapshots )' -- "${cur}" ) )
return return
;; ;;
--newname | -N ) --newname | -N )
@ -851,8 +851,8 @@ _lxc_snapshot() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_snapshot lxc-snapshot complete -F _lxc_snapshot lxc-snapshot
_lxc_start() { _lxc_start() {
@ -860,11 +860,11 @@ _lxc_start() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--daemon | -d | --foreground | -F | --close-all-fds | -C ) --daemon | -d | --foreground | -F | --close-all-fds | -C )
@ -911,8 +911,8 @@ _lxc_start() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_start lxc-start complete -F _lxc_start lxc-start
_lxc_stop() { _lxc_stop() {
@ -920,11 +920,11 @@ _lxc_stop() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -948,8 +948,8 @@ _lxc_stop() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_stop lxc-stop complete -F _lxc_stop lxc-stop
_lxc_top() { _lxc_top() {
@ -957,7 +957,7 @@ _lxc_top() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--batch | -b | --reverse | -r ) --batch | -b | --reverse | -r )
@ -981,7 +981,7 @@ _lxc_top() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
} } &&
complete -F _lxc_top lxc-top complete -F _lxc_top lxc-top
_lxc_unfreeze() { _lxc_unfreeze() {
@ -989,11 +989,11 @@ _lxc_unfreeze() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -1009,8 +1009,8 @@ _lxc_unfreeze() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_unfreeze lxc-unfreeze complete -F _lxc_unfreeze lxc-unfreeze
_lxc_unshare() { _lxc_unshare() {
@ -1018,7 +1018,7 @@ _lxc_unshare() {
COMPREPLY=() COMPREPLY=()
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--namespaces | -s ) --namespaces | -s )
@ -1048,7 +1048,7 @@ _lxc_unshare() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
} } &&
complete -F _lxc_unshare lxc-unshare complete -F _lxc_unshare lxc-unshare
_lxc_update_config() { _lxc_update_config() {
@ -1073,8 +1073,7 @@ _lxc_update_config() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
} &&
}
complete -F _lxc_update_config lxc-update-config complete -F _lxc_update_config lxc-update-config
_lxc_usernsexec() { _lxc_usernsexec() {
@ -1107,18 +1106,18 @@ _lxc_usernsexec() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
} } &&
complete -F _lxc_usernsexec lxc-usernsexec complete -F _lxc_usernsexec lxc-usernsexec
_lxc_wait() { _lxc_wait() {
local cur prev words cword split local cur prev words cword split
_init_completion -s -n : || return _init_completion -s -n : || return
_lxc_common_opt || return __lxc_common_opt || return
case ${prev} in case ${prev} in
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
--rcfile ) --rcfile )
@ -1143,8 +1142,8 @@ _lxc_wait() {
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return return
fi fi
_lxc_append_name __lxc_append_name
} } &&
complete -F _lxc_wait lxc-wait complete -F _lxc_wait lxc-wait
# ex: filetype=sh # ex: filetype=sh