public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Bernhard Voelker <mail@bernhard-voelker.de>
To: util-linux@vger.kernel.org
Cc: Bernhard Voelker <mail@bernhard-voelker.de>
Subject: [PATCH] bash-completion: add swapoff
Date: Wed, 10 Apr 2013 11:36:21 +0200	[thread overview]
Message-ID: <1365586581-30512-1-git-send-email-mail@bernhard-voelker.de> (raw)

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


             reply	other threads:[~2013-04-10  9:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-10  9:36 Bernhard Voelker [this message]
2013-04-10 12:38 ` [PATCH] bash-completion: add swapoff Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365586581-30512-1-git-send-email-mail@bernhard-voelker.de \
    --to=mail@bernhard-voelker.de \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox