Repository navigation
Expand file tree
/
Copy pathcompletion.sdm
More file actions
118 lines (111 loc) · 3.34 KB
/
Copy pathcompletion.sdm
File metadata and controls
118 lines (111 loc) · 3.34 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# sdm completion
#
# This file is part of sdm
#
__contains_word() {
local w word=$1; shift
for w in "$@"; do
[[ $w = "$word" ]] && return
done
}
_sdm() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local i verb comps cur_orig
# Don't include plugin-debug so --plugin works as desired
local -A OPTS=(
[STANDALONE]='--help --apt-dist-upgrade --autologin --batch --bootscripts --chroot
--ddextend --directory --encrypted --expand-at-boot --expand-root
--gpt --no-expand-root --norestart --noreboot --nowait-timesync --oklive
--redact --redo-customize --regen-ssh-host-keys --restart --showapt --version'
[ARG]='--1piboot --aptcache --aptmaint --apt-options --b0script --b1script
--burn --burnfile --burn-plugin --cscript --convert-root --csrc --customize --datefmt --ddsw
--debug --domain --ecolors --explore --extend --extract-log --extract-script --groups --hostname --info --keyfile --logwidth
--mcolors --mount --nspawnsw --os --plugin --poptions --ppart --reboot --runonly --sdmdir --sdmprep --shrink
--bupdate --xmb' # Leave these out so --customize can be shortcutted --custom1 --custom2 --custom3 --custom4
)
_init_completion || return
cur_orig=$cur
if __contains_word "$prev" ${OPTS[ARG]}; then
case $prev in
--aptcache)
COMPREPLY='ip:port'
return 0
;;
--aptmaint)
comps='update upgrade autoremove'
;;
--apt-options|--poptions)
comps='noupdate noupgrade noautoremove nologdates no-install-recommends none'
;;
--b0script|--b1script|--cscript|--csrc|--extract-log|--extract-script|--keyfile)
_filedir
return 0
;;
--burn)
COMPREPLY=( $(compgen -W "$(lsblk -pnro name)" -- $cur) )
return 0
;;
--burnfile)
_filedir
return 0
#comps=$(compgen -A file -- "$cur")
;;
--burn-plugin)
COMPREPLY=( $(compgen -W "string" -- $cur) )
return 0
;;
--convert-root)
comps='btrfs ext4 lvm'
;;
--customize|--explore|--extend|--mount|--ppart|--sdmprep|--shrink)
comps=$(compgen -f -- "$cur")
compopt -o filenames
COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") )
return 0
;;
--info)
comps='time locale keymap wifi-country'
;;
--logwidth|--xmb|--reboot)
COMPREPLY=( $(compgen -W "number" -- $cur) )
return 0
;;
--plugin)
dir=/usr/local/sdm/plugins
pfiles=()
while IFS= read -r f; do
pfiles+=("$f")
done < <(find "$dir" -maxdepth 1 -type f -printf '%f\n' 2>/dev/null)
COMPREPLY=( $(compgen -W "${pfiles[*]}" -- "$cur") )
return 0
;;
--burn-plugin|--custom[1234]|--csrc|--datefmt|--ddsw|--debug|--domain|--ecolors|--groups|--host|--hostname|--mcolors|--nspawnsw|--sdmdir)
COMPREPLY=( $(compgen -W "string" -- $cur) )
return 0
;;
--runonly)
comps='plugins'
;;
-*)
COMPREPLY=( $(compgen -W "${OPTS[STANDALONE]}" -- "$cur") )
return 0
;;
esac
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
fi
# echo "cur:|$cur|"
if [[ "$cur" = -* ]]; then
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
return 0
fi
# Get a naked argument and treat it like a filename
if [[ -z $comps ]]; then
comps=$(compgen -f -- "$cur")
compopt -o filenames
COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") )
fi
return 0
}
complete -F _sdm sdm