public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bash-completion: add swapoff
@ 2013-04-10  9:36 Bernhard Voelker
  2013-04-10 12:38 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Bernhard Voelker @ 2013-04-10  9:36 UTC (permalink / raw)
  To: util-linux; +Cc: Bernhard Voelker

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bash-completion: add swapoff
  2013-04-10  9:36 [PATCH] bash-completion: add swapoff Bernhard Voelker
@ 2013-04-10 12:38 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2013-04-10 12:38 UTC (permalink / raw)
  To: Bernhard Voelker; +Cc: util-linux

On Wed, Apr 10, 2013 at 11:36:21AM +0200, Bernhard Voelker wrote:
>  bash-completion/swapoff | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
>  create mode 100644 bash-completion/swapoff

 Applied, thanks.

> +	case $cur in
> +		-*)
> +			OPTS="-a
> +				-L
> +				-U
> +				-v
> +				--all
> +				--verbose
> +				--help
> +				--version"

 We prefer long options (so I have removed -a and -v).

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-04-10 12:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-10  9:36 [PATCH] bash-completion: add swapoff Bernhard Voelker
2013-04-10 12:38 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox