-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_completion
More file actions
92 lines (87 loc) · 2.99 KB
/
bash_completion
File metadata and controls
92 lines (87 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# bash completion for vm-run
# shellcheck disable=SC2207,SC2155,SC2148
_vm_run()
{
local cur=${COMP_WORDS[$COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local cmd=${1##*/}
if [ "$cur" = '=' ]; then
prev+=$cur
cur=
elif [ "$prev" = '=' ]; then
prev=${COMP_WORDS[COMP_CWORD-2]}$prev
fi
case "$prev" in
--kvm=)
COMPREPLY=( $(compgen -W "all cond only try" -- "$cur") )
return
;;
--bios=)
COMPREPLY=( $(compgen -W "secureboot microvm u-boot uefi" -- "$cur") )
return
;;
--fs=)
COMPREPLY=( $(compgen -W "ext2 ext3 ext4" -- "$cur") )
return
;;
--multidevs=)
COMPREPLY=( $(compgen -W "forbid remap warn" -- "$cur") )
return
;;
--part=)
COMPREPLY=( $(compgen -W "gpt mbr" -- "$cur") )
return
;;
--fat= | --ls= | --create-rootfs=)
compopt -o filenames 2>/dev/null
COMPREPLY=( $(compgen -d -- "$cur") )
return
;;
--drive= | --rootfs= | --rdadd=)
compopt -o filenames 2>/dev/null
COMPREPLY=( $(compgen -f -- "$cur") )
return
;;
--kernel=)
local kernels=$(vm-run --kernels |& grep -Eo '/\S+' | sed 's!^/boot/vmlinuz-!!')
COMPREPLY=( $(compgen -W "\$kernels" -- "$cur") )
return
;;
--loglevel=)
COMPREPLY=( $(compgen -W "0 1 2 3 4 5 6 7 max debug initcall" -- "$cur") )
return
;;
esac
if [[ $cur == -* ]]; then
local script=$(type -p "$cmd")
[ -n "$script" ] || return
local opts=$(awk '/^(for|while) .*; do # opt/' RS= ORS='\n\n' "$script" | grep -Eo '.+[\)]' | grep -Po -e '-[^^)*| ]+')
COMPREPLY=( $(compgen -W "\$opts" -- "$cur") )
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
elif [ "$cmd" = "vm-run" ]; then
COMPREPLY=( $(compgen -c -- "$cur") )
elif [ "$cmd" = "vm-create-image" ]; then
compopt -o filenames 2>/dev/null
COMPREPLY=( $(compgen -f -- "$cur") )
fi
} &&
complete -F _vm_run vm-run vm-create-image
# Very simplistic completion for modprobe, modinfo, and rmmod, just showing
# module names, when bash-completion is not installed.
[ -e /usr/share/bash-completion/completions/modprobe ] ||
_modprobe()
{
local cur=${COMP_WORDS[$COMP_CWORD]}
local root=
[[ "$MODPROBE_OPTIONS" =~ --dirname=([^[:space:]]+) ]] && root=${BASH_REMATCH[1]}
local modpath=$root/lib/modules/$(uname -r)
COMPREPLY=( $(compgen -W "$(grep -sPo '[^/]+(?=\.ko)' "$modpath/modules.order")" -- "$cur") )
} &&
complete -F _modprobe modprobe modinfo
[ -e /usr/share/bash-completion/completions/rmmod ] ||
_rmmod()
{
local cur=${COMP_WORDS[$COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(cut -d' ' -f1 /proc/modules)" -- "$cur") )
} &&
complete -F _rmmod rmmod
# ex: filetype=sh sw=4 et