]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
bash-completion: use swapon label and uuid listing support
authorSami Kerola <kerolasa@iki.fi>
Sun, 26 Oct 2014 22:07:09 +0000 (22:07 +0000)
committerKarel Zak <kzak@redhat.com>
Fri, 31 Oct 2014 09:39:01 +0000 (10:39 +0100)
Simplifies the script, and makes swapoff to work for files when get
requests by label or uuid.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
bash-completion/swapoff
bash-completion/swapon

index 60d85724cdf00f45658ec92c379b2c1a3619b405..40dcf056940fb408caf6640baae1d19d06f773e1 100644 (file)
@@ -9,25 +9,11 @@ _swapoff_module()
                        return 0
                        ;;
                '-U'|'UUID=')
-                       # only works for block devices, i.e., not for swap files.
-                       local SWAPS
-                       SWAPS="$(swapon --show=TYPE,NAME --raw --noheading | \
-                               awk '$1 !~ /file/ { print $2 }')"
-                       [ -z "$SWAPS" ] && return 0
-                       local UUIDS
-                       UUIDS="$(lsblk -nrp -o UUID "$SWAPS")"
-                       COMPREPLY=( $(compgen -W "$UUIDS" -- $cur) )
+                       COMPREPLY=( $(compgen -W "$(swapon --show=UUID --noheading)" -- $cur) )
                        return 0
                        ;;
                '-L'|'LABEL=')
-                       # only works for block devices, i.e., not for swap files.
-                       local SWAPS
-                       SWAPS="$(swapon --show=TYPE,NAME --raw --noheading | \
-                               awk '$1 !~ /file/ { print $2 }')"
-                       [ -z "$SWAPS" ] && return 0
-                       local LABELS
-                       LABELS="$(lsblk -nrp -o LABEL "$SWAPS")"
-                       COMPREPLY=( $(compgen -W "$LABELS" -- $cur) )
+                       COMPREPLY=( $(compgen -W "$(swapon --show=LABEL --noheading)" -- $cur) )
                        return 0
                        ;;
                '-h'|'--help'|'-V'|'--version')
@@ -46,9 +32,7 @@ _swapoff_module()
                        return 0
                        ;;
        esac
-       local DEVS
-       DEVS="$(swapon --show=NAME --raw --noheading)"
-       COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+       COMPREPLY=( $(compgen -W "$(swapon --show=NAME --raw --noheading)" -- $cur) )
        return 0
 }
 complete -F _swapoff_module swapoff
index 7656d4efdbbdbe7eb71b927cf21d7bff3b0a6f52..f471e079cc6781d304afd43923af40aa1e9a7e2b 100644 (file)
@@ -14,7 +14,7 @@ _swapon_module()
                '--show')
                        # FIXME: how to append to a string with compgen?
                        local OUTPUT
-                       OUTPUT="NAME TYPE SIZE USED PRIO"
+                       OUTPUT="NAME TYPE SIZE USED PRIO UUID LABEL"
                        compopt -o nospace
                        COMPREPLY=( $(compgen -W "$OUTPUT" -S ',' -- $cur) )
                        return 0