[PATCH] bash-completion: add swapoff

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Bernhard Voelker <mail@xxxxxxxxxxxxxxxxxxx>
---
 bash-completion/swapoff | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 bash-completion/swapoff

diff --git a/bash-completion/swapoff b/bash-completion/swapoff
new file mode 100644
index 0000000..badc1de
--- /dev/null
+++ b/bash-completion/swapoff
@@ -0,0 +1,56 @@
+_swapoff_module()
+{
+	local cur prev OPTS
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
+	case $prev in
+		'-a'|'--all')
+			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) )
+			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) )
+			return 0
+			;;
+		'-h'|'--help'|'-V'|'--version')
+			return 0
+			;;
+	esac
+	case $cur in
+		-*)
+			OPTS="-a
+				-L
+				-U
+				-v
+				--all
+				--verbose
+				--help
+				--version"
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
+			return 0
+			;;
+	esac
+	local DEVS
+	DEVS="$(swapon --show=NAME --raw --noheading)"
+	COMPREPLY=( $(compgen -W "$DEVS" -- $cur) )
+	return 0
+}
+complete -F _swapoff_module swapoff
-- 
1.8.1.3.619.g7b6e784

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux