From c83f6af3e75d67aa7789c5656f872c4b3aaf49cc Mon Sep 17 00:00:00 2001
From: Kostadin Damyanov <maxmight@gmail.com>
Date: Wed, 23 Sep 2015 22:55:52 +0300
Subject: [PATCH] Add pkgman and finddir support

---
 completions/Makefile.am |  4 +++-
 completions/finddir     | 17 +++++++++++++++++
 completions/pkgman      | 42 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 1 deletion(-)
 create mode 100644 completions/finddir
 create mode 100644 completions/pkgman

diff --git a/completions/Makefile.am b/completions/Makefile.am
index 723b42f..6a66739 100644
--- a/completions/Makefile.am
+++ b/completions/Makefile.am
@@ -467,7 +467,9 @@ bashcomp_DATA = 2to3 \
 		_yum \
 		yum-arch \
 		zopfli \
-		zopflipng
+		zopflipng \
+		pkgman \
+		finddir
 
 EXTRA_DIST = $(bashcomp_DATA)
 
diff --git a/completions/finddir b/completions/finddir
new file mode 100644
index 0000000..cf7f6e4
--- /dev/null
+++ b/completions/finddir
@@ -0,0 +1,17 @@
+_finddir()
+{
+	local cur words
+	_init_completion || return
+
+	COMPREPLY=()
+	cur=${COMP_WORDS[COMP_CWORD]}
+
+	if [[ "$cur" == -* ]]; then
+		COMPREPLY=( $( compgen -W '-l -v' -- "$cur" ) )
+	else
+		COMPREPLY=( $( compgen -W '$( finddir -l )' -- "$cur" ) )
+	fi
+
+	return 0
+} &&
+complete -F _finddir finddir
diff --git a/completions/pkgman b/completions/pkgman
new file mode 100644
index 0000000..f1f942f
--- /dev/null
+++ b/completions/pkgman
@@ -0,0 +1,42 @@
+_pkgman()
+{
+	local cur words
+	_init_completion || return
+
+	COMPREPLY=()
+	cur=${COMP_WORDS[COMP_CWORD]}
+
+	local special i
+	for (( i=0; i < ${#words[@]}-1; i++ )); do
+		if [[ ${words[i]} == @(install|uninstall) ]]; then
+			special=${words[i]}
+		fi
+	done
+
+	if [[ -n $special ]]; then
+		case $special in
+			install)
+				COMPREPLY=( $( compgen -W "$( pkgman search -a -D | awk 'NR>2 { print $2 }' )" -- "$cur" ) )
+				return 0
+				;;
+			uninstall)
+				COMPREPLY=( $( compgen -W "$( pkgman search -a -i | awk 'NR>2 { print $2 }' )" -- "$cur" ) )
+				return 0
+				;;
+			*)
+				return 0
+				;;
+		esac
+	fi
+
+	if [[ "$cur" == -* ]]; then
+		COMPREPLY=( $( compgen -W '-h --help' -- "$cur" ) )
+	else
+		COMPREPLY=( $( compgen -W 'full-sync install search \
+			uninstall update add-repo drop-repo list-repos refresh \
+			resolve-dependencies' -- "$cur" ) )
+	fi
+
+	return 0
+} &&
+complete -F _pkgman pkgman
-- 
2.30.0

