bash-completion: add swapon specifiers to completion

No space after device name is not entirely right, but that's better than
missing argument completions.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2018-05-10 21:02:00 +01:00 committed by Karel Zak
parent 25ed963d02
commit faa44b6d9a
1 changed files with 18 additions and 3 deletions

View File

@ -25,18 +25,30 @@ _swapon_module()
COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) )
return 0
;;
'-U')
'-U'|'UUID=')
local UUIDS
UUIDS="$(lsblk -nrp -o FSTYPE,UUID | awk '$1 ~ /swap/ { print $2 }')"
COMPREPLY=( $(compgen -W "$UUIDS" -- $cur) )
return 0
;;
'-L')
'-L'|'LABEL=')
local LABELS
LABELS="$(lsblk -nrp -o FSTYPE,LABEL | awk '$1 ~ /swap/ { print $2 }')"
COMPREPLY=( $(compgen -W "$LABELS" -- $cur) )
return 0
;;
'PARTUUID=')
local PARTUUIDS
PARTUUIDS="$(lsblk -nrp -o FSTYPE,PARTUUID | awk '$1 ~ /swap/ { print $2 }')"
COMPREPLY=( $(compgen -W "$PARTUUIDS" -- $cur) )
return 0
;;
'PARTLABEL=')
local PARTLABELS
PARTLABELS="$(lsblk -nrp -o FSTYPE,PARTLABEL | awk '$1 ~ /swap/ { print $2 }')"
COMPREPLY=( $(compgen -W "$PARTLABELS" -- $cur) )
return 0
;;
'-h'|'--help'|'-V'|'--version')
return 0
;;
@ -55,6 +67,8 @@ _swapon_module()
--raw
--bytes
--verbose
-L
-U
--help
--version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
@ -63,7 +77,8 @@ _swapon_module()
esac
local DEVS
DEVS="$(lsblk -nrp -o FSTYPE,NAME | awk '$1 ~ /swap/ { print $2 }')"
COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
compopt -o nospace
COMPREPLY=( $(compgen -fW "$DEVS LABEL= UUID= PARTLABEL= PARTUUID=" -- $cur) )
return 0
}
complete -F _swapon_module swapon