Skip to content

Commit

Permalink
bash-completion: add swapon specifiers to completion
Browse files Browse the repository at this point in the history
No space after device name is not entirely right, but that's better than
missing argument completions.

Signed-off-by: Sami Kerola <[email protected]>
  • Loading branch information
kerolasa authored and karelzak committed May 28, 2018
1 parent 25ed963 commit faa44b6
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions bash-completion/swapon
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand All @@ -55,6 +67,8 @@ _swapon_module()
--raw
--bytes
--verbose
-L
-U
--help
--version"
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
Expand All @@ -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

0 comments on commit faa44b6

Please sign in to comment.