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