Updated and improved completetion function
This commit is contained in:
parent
fd781409f1
commit
fa02cc2231
|
@ -1,5 +1,6 @@
|
|||
#!/bin/bash
|
||||
#shellcheck disable=1090 disable=2012
|
||||
# Bash completion for qq2clone
|
||||
|
||||
_qq2clone () {
|
||||
|
||||
[[ -e "${HOME:?}/.config/qq2clone" ]] || return 1
|
||||
QQ2_DIR="$(<"${HOME}/.config/qq2clone")"
|
||||
|
@ -17,13 +18,10 @@ while read -r line; do
|
|||
templates=( "${templates[@]}" "$line" )
|
||||
done < <("${QQ2_DIR}/sqlite3" --batch "${QQ2_DIR}/qq2clone.db" \
|
||||
"select name from TEMPLATES")
|
||||
|
||||
_qq2clone ()
|
||||
{
|
||||
declare -a COMS FLAGS
|
||||
COMS=( check clone config connect copy-template delete-template destroy \
|
||||
edit exec import-template list list-templates modify-template restore \
|
||||
resume rm rm-save save shred shred-save start suspend )
|
||||
resume rm rm-shred rm-wipe save save-rm start suspend )
|
||||
FLAGS=( connection no-spice use-spice help no-run quiet quieter run spicy \
|
||||
storage template verbose virt-viewer )
|
||||
|
||||
|
@ -33,8 +31,9 @@ local LAST_ARG THIS_ARG B4_LAST_ARG P set_coms
|
|||
(( COMP_CWORD > 1 )) &&
|
||||
B4_LAST_ARG="${COMP_WORDS[$((COMP_CWORD - 2))]}"
|
||||
THIS_ARG="${COMP_WORDS[$COMP_CWORD]}"
|
||||
set_coms="connect|destroy|exec|resume|rm|rm\-save|save|shred|shred\-save|"
|
||||
set_coms="connect|destroy|exec|resume|rm|rm\-shred|rm\-wipe|save|save\-rm|"
|
||||
set_coms="${set_coms}start|suspend|restore"
|
||||
|
||||
declare -a suggestions
|
||||
|
||||
if [[ "$THIS_ARG" =~ ^\-\- ]]; then
|
||||
|
@ -70,15 +69,6 @@ else
|
|||
elif [[ "$curr_com" == config ]] &&
|
||||
[[ "${COMP_WORDS[$((COMP_CWORD - 2))]}" == "$curr_com" ]] &&
|
||||
[[ "$LAST_ARG" =~ ^(info|edit)$ ]]; then
|
||||
local line
|
||||
while read -r line; do
|
||||
[[ "$line" =~ \
|
||||
^[[:space:]]*([^[:space:]].*[^[:space:]])[[:space:]]*$ ]] &&
|
||||
line="${BASH_REMATCH[1]}"
|
||||
[[ "$line" =~ ^# ]] && continue
|
||||
[[ "$line" =~ ^([^=]+).* ]] &&
|
||||
suggestions=( "${suggestions[@]}" "${BASH_REMATCH[1]}" )
|
||||
done <"${QQ2_DIR}/config"
|
||||
suggestions=(NORUN QUIET USE_SPICE SPICY STORAGE S_TIMEOUT TEMPLATE \
|
||||
TEMPLATE_DIR)
|
||||
else
|
||||
|
@ -103,3 +93,5 @@ read -ra COMPREPLY < <(compgen -P "${P}" -W "${comp[*]}" | tr "\n" " ")
|
|||
}
|
||||
|
||||
complete -F _qq2clone qq2clone
|
||||
|
||||
# End bash completion for qq2clone
|
||||
|
|
Loading…
Reference in New Issue