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