2013-03-24 17:19:09 +00:00
|
|
|
_losetup_module()
|
|
|
|
{
|
|
|
|
local cur prev OPTS ARG
|
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
case $prev in
|
|
|
|
'-d'|'--detach')
|
2014-11-15 22:36:04 +02:00
|
|
|
ARG="$($1 --output NAME | awk '{if (1 < NR) {print}}')"
|
2013-03-24 17:19:09 +00:00
|
|
|
COMPREPLY=( $(compgen -W "$ARG" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-j'|'--associated')
|
2014-11-15 22:36:04 +02:00
|
|
|
ARG="$($1 --output BACK-FILE | awk '{if (1 < NR) {print}}')"
|
2013-03-24 17:19:09 +00:00
|
|
|
COMPREPLY=( $(compgen -W "$ARG" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-c'|'--set-capacity')
|
|
|
|
ARG="$(for I in /dev/loop[0-9]*; do if [ -e $I ]; then echo $I; fi; done)"
|
|
|
|
COMPREPLY=( $(compgen -W "$ARG" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
'-o'|'--offset'|'--sizelimit')
|
|
|
|
COMPREPLY=( $(compgen -W "number" -- $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 23:59:01 +06:00
|
|
|
local prefix realcur OUTPUT_ALL OUTPUT
|
|
|
|
realcur="${cur##*,}"
|
|
|
|
prefix="${cur%$realcur}"
|
|
|
|
OUTPUT_ALL="NAME AUTOCLEAR BACK-FILE BACK-INO
|
2013-03-24 17:19:09 +00:00
|
|
|
BACK-MAJ:MIN MAJ:MIN OFFSET PARTSCAN RO
|
|
|
|
SIZELIMIT"
|
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 23:59:01 +06:00
|
|
|
for WORD in $OUTPUT_ALL; do
|
|
|
|
if ! [[ $prefix == *"$WORD"* ]]; then
|
|
|
|
OUTPUT="$WORD $OUTPUT"
|
|
|
|
fi
|
|
|
|
done
|
2013-03-24 17:19:09 +00: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 23:59:01 +06:00
|
|
|
COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) )
|
2013-03-24 17:19:09 +00:00
|
|
|
return 0
|
|
|
|
;;
|
2013-04-07 11:12:04 +03:00
|
|
|
'-h'|'--help'|'-V'|'--version')
|
|
|
|
return 0
|
|
|
|
;;
|
2013-03-24 17:19:09 +00:00
|
|
|
esac
|
|
|
|
case $cur in
|
|
|
|
-*)
|
2013-04-07 11:12:08 +03:00
|
|
|
OPTS="--all
|
|
|
|
--detach
|
|
|
|
--detach-all
|
|
|
|
--find
|
|
|
|
--set-capacity
|
|
|
|
--associated
|
|
|
|
--list
|
|
|
|
--offset
|
|
|
|
--output
|
|
|
|
--sizelimit
|
|
|
|
--partscan
|
|
|
|
--read-only
|
|
|
|
--show
|
|
|
|
--verbose
|
|
|
|
--help
|
|
|
|
--version"
|
2013-03-24 17:19:09 +00:00
|
|
|
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
2013-09-30 15:49:00 +02:00
|
|
|
local IFS=$'\n'
|
2013-03-24 17:19:09 +00:00
|
|
|
compopt -o filenames
|
|
|
|
COMPREPLY=( $(compgen -f -- $cur) )
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
complete -F _losetup_module losetup
|