2014-08-03 09:10:50 -05:00
|
|
|
_zramctl_module()
|
|
|
|
{
|
|
|
|
local cur prev OPTS
|
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
case $prev in
|
|
|
|
'-a'|'--algorithm')
|
|
|
|
COMPREPLY=( $(compgen -W "lzo lz4" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-o'|'--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
|
|
|
local prefix realcur OUTPUT_ALL OUTPUT
|
|
|
|
realcur="${cur##*,}"
|
|
|
|
prefix="${cur%$realcur}"
|
|
|
|
OUTPUT_ALL="NAME DISKSIZE DATA COMPR ALGORITHM STREAMS ZERO-PAGES TOTAL MOUNTPOINT"
|
|
|
|
for WORD in $OUTPUT_ALL; do
|
|
|
|
if ! [[ $prefix == *"$WORD"* ]]; then
|
|
|
|
OUTPUT="$WORD $OUTPUT"
|
|
|
|
fi
|
|
|
|
done
|
2014-08-03 09:10:50 -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) )
|
2014-08-03 09:10:50 -05:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-s'|'--size')
|
|
|
|
COMPREPLY=( $(compgen -W "size" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-t'|'--streams')
|
|
|
|
COMPREPLY=( $(compgen -W "number" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case $cur in
|
|
|
|
-*)
|
|
|
|
OPTS=" --algorithm
|
|
|
|
--bytes
|
|
|
|
--find
|
|
|
|
--noheadings
|
|
|
|
--output
|
|
|
|
--raw
|
|
|
|
--reset
|
|
|
|
--size
|
|
|
|
--streams
|
|
|
|
--help
|
|
|
|
--version"
|
|
|
|
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
local IFS=$'\n'
|
|
|
|
compopt -o filenames
|
|
|
|
COMPREPLY=( $(compgen -f -- ${cur:-"/dev/zram"}) )
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
complete -F _zramctl_module zramctl
|