| 1 |
# cryptdisks_{start,stop} completion by first column of crypttab |
| 2 |
# |
| 3 |
# Copyright 2013 Claudius Hubig <[email protected]>, 2-clause BSD |
| 4 |
|
| 5 |
_cryptdisks() { |
| 6 |
local action="$1" t |
| 7 |
for t in $( awk -vt="${COMP_WORDS[COMP_CWORD]}" \ |
| 8 |
'($1 !~ /^#/ && index($1,t) == 1) {print $1}' \ |
| 9 |
"${TABFILE-"/etc/crypttab"}" ); do |
| 10 |
if [ "$action" = start -a ! -e "/dev/mapper/$t" ] || |
| 11 |
[ "$action" = stop -a -e "/dev/mapper/$t" ]; then |
| 12 |
COMPREPLY+=( "$t" ) |
| 13 |
fi |
| 14 |
done |
| 15 |
return 0; |
| 16 |
} |
| 17 |
|
| 18 |
_cryptdisks_start() { |
| 19 |
local i include_options=y |
| 20 |
COMPREPLY=() |
| 21 |
for (( i=0; i < COMP_CWORD-1; i++ )); do |
| 22 |
if [ "${COMP_WORDS[i]}" = "--" ] || [[ "${COMP_WORDS[i]}" != -* ]]; then |
| 23 |
include_options=n |
| 24 |
break |
| 25 |
fi |
| 26 |
done |
| 27 |
if [ "$include_options" = "y" ]; then |
| 28 |
for i in "-r" "--readonly" "--"; do |
| 29 |
if [[ "$i" == "${COMP_WORDS[COMP_CWORD]}"* ]]; then |
| 30 |
COMPREPLY+=( "$i" ) |
| 31 |
fi |
| 32 |
done |
| 33 |
fi |
| 34 |
_cryptdisks start "$@" |
| 35 |
} |
| 36 |
_cryptdisks_stop() { |
| 37 |
COMPREPLY=() |
| 38 |
_cryptdisks stop "$@"; |
| 39 |
} |
| 40 |
|
| 41 |
complete -F _cryptdisks_start cryptdisks_start |
| 42 |
complete -F _cryptdisks_stop cryptdisks_stop |