]>
Commit | Line | Data |
---|---|---|
c6f8c3f5 SK |
1 | _swapon_module() |
2 | { | |
3 | local cur prev OPTS | |
4 | COMPREPLY=() | |
5 | cur="${COMP_WORDS[COMP_CWORD]}" | |
6 | prev="${COMP_WORDS[COMP_CWORD-1]}" | |
7 | case $prev in | |
8 | '-p'|'--priority') | |
9 | # Priority range is -1 to 32767. Perhaps these | |
10 | # few are enough. | |
d6b975ef | 11 | COMPREPLY=( $(compgen -W "{-1..9} 32767" -- $cur) ) |
c6f8c3f5 SK |
12 | return 0 |
13 | ;; | |
14 | '--show') | |
b5b80e5a BE |
15 | local prefix realcur OUTPUT_ALL OUTPUT |
16 | realcur="${cur##*,}" | |
17 | prefix="${cur%$realcur}" | |
18 | OUTPUT_ALL="NAME TYPE SIZE USED PRIO UUID LABEL" | |
19 | for WORD in $OUTPUT_ALL; do | |
20 | if ! [[ $prefix == *"$WORD"* ]]; then | |
abbcec4f | 21 | OUTPUT="$WORD ${OUTPUT:-""}" |
b5b80e5a BE |
22 | fi |
23 | done | |
c6f8c3f5 | 24 | compopt -o nospace |
b5b80e5a | 25 | COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) ) |
c6f8c3f5 SK |
26 | return 0 |
27 | ;; | |
faa44b6d | 28 | '-U'|'UUID=') |
a6f58362 SK |
29 | local UUIDS |
30 | UUIDS="$(lsblk -nrp -o FSTYPE,UUID | awk '$1 ~ /swap/ { print $2 }')" | |
31 | COMPREPLY=( $(compgen -W "$UUIDS" -- $cur) ) | |
32 | return 0 | |
33 | ;; | |
faa44b6d | 34 | '-L'|'LABEL=') |
a6f58362 SK |
35 | local LABELS |
36 | LABELS="$(lsblk -nrp -o FSTYPE,LABEL | awk '$1 ~ /swap/ { print $2 }')" | |
37 | COMPREPLY=( $(compgen -W "$LABELS" -- $cur) ) | |
38 | return 0 | |
39 | ;; | |
faa44b6d SK |
40 | 'PARTUUID=') |
41 | local PARTUUIDS | |
42 | PARTUUIDS="$(lsblk -nrp -o FSTYPE,PARTUUID | awk '$1 ~ /swap/ { print $2 }')" | |
43 | COMPREPLY=( $(compgen -W "$PARTUUIDS" -- $cur) ) | |
44 | return 0 | |
45 | ;; | |
46 | 'PARTLABEL=') | |
47 | local PARTLABELS | |
48 | PARTLABELS="$(lsblk -nrp -o FSTYPE,PARTLABEL | awk '$1 ~ /swap/ { print $2 }')" | |
49 | COMPREPLY=( $(compgen -W "$PARTLABELS" -- $cur) ) | |
50 | return 0 | |
51 | ;; | |
d4f9b8d7 VS |
52 | '-h'|'--help'|'-V'|'--version') |
53 | return 0 | |
54 | ;; | |
c6f8c3f5 SK |
55 | esac |
56 | case $cur in | |
57 | -*) | |
0d5b9b8a VS |
58 | OPTS="--all |
59 | --discard | |
60 | --ifexists | |
61 | --fixpgsz | |
62 | --priority | |
63 | --summary | |
64 | --show | |
b5b43f27 | 65 | --output-all |
0d5b9b8a VS |
66 | --noheadings |
67 | --raw | |
68 | --bytes | |
69 | --verbose | |
faa44b6d SK |
70 | -L |
71 | -U | |
0d5b9b8a VS |
72 | --help |
73 | --version" | |
c6f8c3f5 SK |
74 | COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) |
75 | return 0 | |
76 | ;; | |
77 | esac | |
a6f58362 SK |
78 | local DEVS |
79 | DEVS="$(lsblk -nrp -o FSTYPE,NAME | awk '$1 ~ /swap/ { print $2 }')" | |
faa44b6d SK |
80 | compopt -o nospace |
81 | COMPREPLY=( $(compgen -fW "$DEVS LABEL= UUID= PARTLABEL= PARTUUID=" -- $cur) ) | |
c6f8c3f5 SK |
82 | return 0 |
83 | } | |
84 | complete -F _swapon_module swapon |