dcavalca / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
531551
From 0b8ef4d8289fa1af0296ae01faf0e60293c725fd Mon Sep 17 00:00:00 2001
531551
From: Karel Zak <kzak@redhat.com>
531551
Date: Wed, 22 Mar 2017 12:13:43 +0100
531551
Subject: [PATCH] zramctl: add bash completion
531551
531551
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1358755
531551
Signed-off-by: Karel Zak <kzak@redhat.com>
531551
---
531551
 bash-completion/Makemodule.am |  3 ++-
531551
 bash-completion/zramctl       | 57 +++++++++++++++++++++++++++++++++++++++++++
531551
 2 files changed, 59 insertions(+), 1 deletion(-)
531551
 create mode 100644 bash-completion/zramctl
531551
531551
diff --git a/bash-completion/Makemodule.am b/bash-completion/Makemodule.am
531551
index c3791e7..84ab258 100644
531551
--- a/bash-completion/Makemodule.am
531551
+++ b/bash-completion/Makemodule.am
531551
@@ -30,7 +30,8 @@ dist_bashcompletion_DATA = \
531551
 	bash-completion/setsid \
531551
 	bash-completion/tailf \
531551
 	bash-completion/whereis \
531551
-	bash-completion/wipefs
531551
+	bash-completion/wipefs \
531551
+	bash-completion/zramctl
531551
 
531551
 # disk-utils...
531551
 if BUILD_BFS
531551
diff --git a/bash-completion/zramctl b/bash-completion/zramctl
531551
new file mode 100644
531551
index 0000000..a4ef536
531551
--- /dev/null
531551
+++ b/bash-completion/zramctl
531551
@@ -0,0 +1,57 @@
531551
+_zramctl_module()
531551
+{
531551
+	local cur prev OPTS
531551
+	COMPREPLY=()
531551
+	cur="${COMP_WORDS[COMP_CWORD]}"
531551
+	prev="${COMP_WORDS[COMP_CWORD-1]}"
531551
+	case $prev in
531551
+		'-a'|'--algorithm')
531551
+			COMPREPLY=( $(compgen -W "lzo lz4" -- $cur) )
531551
+			return 0
531551
+			;;
531551
+		'-o'|'--output')
531551
+			local prefix realcur OUTPUT_ALL OUTPUT
531551
+			realcur="${cur##*,}"
531551
+			prefix="${cur%$realcur}"
531551
+			OUTPUT_ALL="NAME DISKSIZE DATA COMPR ALGORITHM STREAMS ZERO-PAGES TOTAL MOUNTPOINT"
531551
+			for WORD in $OUTPUT_ALL; do
531551
+				if ! [[ $prefix == *"$WORD"* ]]; then
531551
+					OUTPUT="$WORD $OUTPUT"
531551
+				fi
531551
+			done
531551
+			compopt -o nospace
531551
+			COMPREPLY=( $(compgen -P "$prefix" -W "$OUTPUT" -S ',' -- $realcur) )
531551
+			return 0
531551
+			;;
531551
+		'-s'|'--size')
531551
+			COMPREPLY=( $(compgen -W "size" -- $cur) )
531551
+			return 0
531551
+			;;
531551
+		'-t'|'--streams')
531551
+			COMPREPLY=( $(compgen -W "number" -- $cur) )
531551
+			return 0
531551
+			;;
531551
+	esac
531551
+	case $cur in
531551
+		-*)
531551
+			OPTS="	--algorithm
531551
+				--bytes
531551
+				--find
531551
+				--noheadings
531551
+				--output
531551
+				--raw
531551
+				--reset
531551
+				--size
531551
+				--streams
531551
+				--help
531551
+				--version"
531551
+			COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
531551
+			return 0
531551
+			;;
531551
+	esac
531551
+	local IFS=$'\n'
531551
+	compopt -o filenames
531551
+	COMPREPLY=( $(compgen -f -- ${cur:-"/dev/zram"}) )
531551
+	return 0
531551
+}
531551
+complete -F _zramctl_module zramctl
531551
-- 
531551
2.9.3
531551