]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
bash-completion: swapon: add options and fix argument
authorSami Kerola <kerolasa@iki.fi>
Mon, 8 Apr 2013 19:32:48 +0000 (20:32 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 9 Apr 2013 10:17:15 +0000 (12:17 +0200)
The initial bash-completion missed swapon options -L and -U.  Use of
block device was proposed to be more appropriate than a path to a file.

Requested-by: Karel Zak <kzak@redhat.com>
References: http://marc.info/?l=util-linux-ng&m=136517310727426&w=2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
bash-completion/swapon

index e1271539b8e107bb42a90ac22e12e668c5e30d5f..7656d4efdbbdbe7eb71b927cf21d7bff3b0a6f52 100644 (file)
@@ -19,6 +19,18 @@ _swapon_module()
                        COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
                        return 0
                        ;;
+               '-U')
+                       local UUIDS
+                       UUIDS="$(lsblk -nrp -o FSTYPE,UUID | awk '$1 ~ /swap/ { print $2 }')"
+                       COMPREPLY=( $(compgen -W "$UUIDS" -- $cur) )
+                       return 0
+                       ;;
+               '-L')
+                       local LABELS
+                       LABELS="$(lsblk -nrp -o FSTYPE,LABEL | awk '$1 ~ /swap/ { print $2 }')"
+                       COMPREPLY=( $(compgen -W "$LABELS" -- $cur) )
+                       return 0
+                       ;;
                '-h'|'--help'|'-V'|'--version')
                        return 0
                        ;;
@@ -42,10 +54,9 @@ _swapon_module()
                        return 0
                        ;;
        esac
-       # FIXME: compgen will split SPEC= from '=' point.  The append
-       # comma separated value problem is very similar.
-       compopt -o filenames
-       COMPREPLY=( $(compgen -f -- $cur) )
+       local DEVS
+       DEVS="$(lsblk -nrp -o FSTYPE,NAME | awk '$1 ~ /swap/ { print $2 }')"
+       COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
        return 0
 }
 complete -F _swapon_module swapon