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
@ -112,7 +112,7 @@ _lxc_common_opt() {
return 1 return 1
;; ;;
--logpriority | -l ) --logpriority | -l )
COMPREPLY=( $(compgen -W 'FATAL CRIT WARN ERROR NOTICE INFO DEBUG' -- "${cur}") ) COMPREPLY=( $( compgen -W 'FATAL CRIT WARN ERROR NOTICE INFO DEBUG' -- "${cur}" ) )
return 1 return 1
;; ;;
--quiet | -q ) --quiet | -q )
@ -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,9 +304,9 @@ _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() {
declare -A groups declare -A 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,19 +347,19 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,20 +375,20 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,9 +415,9 @@ _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() {
local cur prev words cword split local cur prev words cword split
@ -426,24 +426,24 @@ _lxc_config() {
$split && return $split && return
if [[ ${cur} == -* ]]; then if [[ ${cur} == -* ]]; then
COMPREPLY=($(compgen -W '-l' -- "${cur}")) COMPREPLY=( $( compgen -W '-l' -- "${cur}" ) )
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
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() {
local cur prev words cword split local cur prev words cword split
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,9 +468,9 @@ _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() {
COMPREPLY=( $( compgen -W 'best btrfs dir loop lvm nbd overlay overlayfs rbd zfs' -- "${cur}" ) ) COMPREPLY=( $( compgen -W 'best btrfs dir loop lvm nbd overlay overlayfs rbd zfs' -- "${cur}" ) )
@ -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,9 +519,9 @@ _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() {
COMPREPLY=( $( compgen -W "$(command ls @LXCTEMPLATEDIR@/ | command sed -e 's|^lxc-||' )" -- "${cur}" ) ) COMPREPLY=( $( compgen -W "$(command ls @LXCTEMPLATEDIR@/ | command sed -e 's|^lxc-||' )" -- "${cur}" ) )
@ -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,19 +564,19 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,9 +595,9 @@ _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() {
local cur prev words cword split local cur prev words cword split
@ -609,12 +609,12 @@ _lxc_device() {
return return
;; ;;
--name | -n ) --name | -n )
_lxc_names __lxc_names
return return
;; ;;
add ) add )
_available_interfaces _available_interfaces
COMPREPLY+=( $(compgen -f -d -X "!*/?*" -- "${cur:-/dev/}") ) COMPREPLY+=( $( compgen -f -d -X "!*/?*" -- "${cur:-/dev/}" ) )
return return
;; ;;
esac esac
@ -626,20 +626,20 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,20 +672,20 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,20 +701,20 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,20 +851,20 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,20 +911,20 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,16 +948,16 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,19 +981,19 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,16 +1009,16 @@ _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() {
local cur prev words cword split local cur prev words cword split
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,8 +1048,8 @@ _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() {
local cur prev words cword split local cur prev words cword split
@ -1073,9 +1073,8 @@ _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() {
local cur prev words cword split local cur prev words cword split
@ -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