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