2013-03-24 12:19:09 -05:00
|
|
|
_swapon_module()
|
|
|
|
{
|
|
|
|
local cur prev OPTS
|
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
case $prev in
|
|
|
|
'-p'|'--priority')
|
|
|
|
# Priority range is -1 to 32767. Perhaps these
|
|
|
|
# few are enough.
|
2013-04-07 03:12:05 -05:00
|
|
|
COMPREPLY=( $(compgen -W "{-1..9} 32767" -- $cur) )
|
2013-03-24 12:19:09 -05:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'--show')
|
bash-completion: handle comma-separated options
This solution can become messy when you have too many options listed,
because it repeats all of them. For example, after invoking completion
with this input:
$ partx --output END,SECTORS,SCHEME,START,
You got these completions:
END,SECTORS,SCHEME,START,FLAGS, END,SECTORS,SCHEME,START,NR,
END,SECTORS,SCHEME,START,TYPE,
END,SECTORS,SCHEME,START,NAME, END,SECTORS,SCHEME,START,SIZE,
END,SECTORS,SCHEME,START,UUID,
Nevertheless, it works even with numbers (listed options properly
excluded from completion). Try to invoke completion after
'chcpu --disable ' or 'lsblk --exclude ' to see it in action.
Few issues remained:
* completion interrupts after encountering ':' in listed option,
like in 'MAJ:MIN' in lsblk, losetup.
* lscpu completion is broken: it inserts space after '--extended',
but lscpu assumes there is no space after this option. It also
doesn't complete '--parse' option.
* some completion options are outdated (for example, lscpu MMHZ). We
need to sync them with code. Fix for lscpu follows.
Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-02 12:59:01 -05:00
|
|
|
local prefix realcur OUTPUT_ALL OUTPUT
|
|
|
|
realcur="${cur##*,}"
|
|
|
|
prefix="${cur%$realcur}"
|
|
|
|
OUTPUT_ALL="NAME TYPE SIZE USED PRIO UUID LABEL"
|
|
|
|
for WORD in $OUTPUT_ALL; do
|
|
|
|
if ! [[ $prefix == *"$WORD"* ]]; then
|
2017-06-30 17:13:58 -05:00
|
|
|
OUTPUT="$WORD ${OUTPUT:-""}"
|
bash-completion: handle comma-separated options
This solution can become messy when you have too many options listed,
because it repeats all of them. For example, after invoking completion
with this input:
$ partx --output END,SECTORS,SCHEME,START,
You got these completions:
END,SECTORS,SCHEME,START,FLAGS, END,SECTORS,SCHEME,START,NR,
END,SECTORS,SCHEME,START,TYPE,
END,SECTORS,SCHEME,START,NAME, END,SECTORS,SCHEME,START,SIZE,
END,SECTORS,SCHEME,START,UUID,
Nevertheless, it works even with numbers (listed options properly
excluded from completion). Try to invoke completion after
'chcpu --disable ' or 'lsblk --exclude ' to see it in action.
Few issues remained:
* completion interrupts after encountering ':' in listed option,
like in 'MAJ:MIN' in lsblk, losetup.
* lscpu completion is broken: it inserts space after '--extended',
but lscpu assumes there is no space after this option. It also
doesn't complete '--parse' option.
* some completion options are outdated (for example, lscpu MMHZ). We
need to sync them with code. Fix for lscpu follows.
Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-02 12:59:01 -05:00
|
|
|
fi
|
|
|
|
done
|
2013-03-24 12:19:09 -05:00
|
|
|
compopt -o nospace
|
bash-completion: handle comma-separated options
This solution can become messy when you have too many options listed,
because it repeats all of them. For example, after invoking completion
with this input:
$ partx --output END,SECTORS,SCHEME,START,
You got these completions:
END,SECTORS,SCHEME,START,FLAGS, END,SECTORS,SCHEME,START,NR,
END,SECTORS,SCHEME,START,TYPE,
END,SECTORS,SCHEME,START,NAME, END,SECTORS,SCHEME,START,SIZE,
END,SECTORS,SCHEME,START,UUID,
Nevertheless, it works even with numbers (listed options properly
excluded from completion). Try to invoke completion after
'chcpu --disable ' or 'lsblk --exclude ' to see it in action.
Few issues remained:
* completion interrupts after encountering ':' in listed option,
like in 'MAJ:MIN' in lsblk, losetup.
* lscpu completion is broken: it inserts space after '--extended',
but lscpu assumes there is no space after this option. It also
doesn't complete '--parse' option.
* some completion options are outdated (for example, lscpu MMHZ). We
need to sync them with code. Fix for lscpu follows.
Signed-off-by: Boris Egorov <egorov@linux.com>
2015-06-02 12:59:01 -05:00
|
|
|
COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) )
|
2013-03-24 12:19:09 -05:00
|
|
|
return 0
|
|
|
|
;;
|
2013-04-08 14:32:48 -05:00
|
|
|
'-U')
|
|
|
|
local UUIDS
|
|
|
|
UUIDS="$(lsblk -nrp -o FSTYPE,UUID | awk '$1 ~ /swap/ { print $2 }')"
|
|
|
|
COMPREPLY=( $(compgen -W "$UUIDS" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-L')
|
|
|
|
local LABELS
|
|
|
|
LABELS="$(lsblk -nrp -o FSTYPE,LABEL | awk '$1 ~ /swap/ { print $2 }')"
|
|
|
|
COMPREPLY=( $(compgen -W "$LABELS" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
2013-04-07 03:12:04 -05:00
|
|
|
'-h'|'--help'|'-V'|'--version')
|
|
|
|
return 0
|
|
|
|
;;
|
2013-03-24 12:19:09 -05:00
|
|
|
esac
|
|
|
|
case $cur in
|
|
|
|
-*)
|
2013-04-07 03:12:08 -05:00
|
|
|
OPTS="--all
|
|
|
|
--discard
|
|
|
|
--ifexists
|
|
|
|
--fixpgsz
|
|
|
|
--priority
|
|
|
|
--summary
|
|
|
|
--show
|
|
|
|
--noheadings
|
|
|
|
--raw
|
|
|
|
--bytes
|
|
|
|
--verbose
|
|
|
|
--help
|
|
|
|
--version"
|
2013-03-24 12:19:09 -05:00
|
|
|
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
2013-04-08 14:32:48 -05:00
|
|
|
local DEVS
|
|
|
|
DEVS="$(lsblk -nrp -o FSTYPE,NAME | awk '$1 ~ /swap/ { print $2 }')"
|
|
|
|
COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
|
2013-03-24 12:19:09 -05:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
complete -F _swapon_module swapon
|