[gnome-control-center] shell: Add bash completion file



commit 4ce6d0a7ab7124f4ad6dae6def38ae7f231fdfa2
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Dec 20 22:48:49 2012 +0100

    shell: Add bash completion file
    
    Only completes the panel names for now.

 shell/Makefile.am                             |    6 +++
 shell/gnome_control_center_completion.bash.in |   43 +++++++++++++++++++++++++
 shell/list-panel.sh                           |    8 +++++
 3 files changed, 57 insertions(+), 0 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 9acb9fc..9c8b2a1 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -78,6 +78,12 @@ sys_in_files = gnome-control-center.desktop.in
 sys_DATA = $(sys_in_files:.desktop.in=.desktop)
 @INTLTOOL_DESKTOP_RULE@
 
+completiondir = $(datadir)/bash-completion/completions
+completion_in_files = gnome_control_center_completion.bash.in
+completion_DATA = $(completion_in_files:.bash.in=.bash)
+gnome_control_center_completion.bash: gnome_control_center_completion.bash.in list-panel.sh
+	$(AM_V_GEN) cat $< | sed "s,@PANELS@,`$(srcdir)/list-panel.sh $(top_srcdir)`," > $@
+
 EXTRA_DIST =					\
 	$(ui_DATA)				\
 	gnome-control-center.desktop.in.in
diff --git a/shell/gnome_control_center_completion.bash.in b/shell/gnome_control_center_completion.bash.in
new file mode 100644
index 0000000..37e6830
--- /dev/null
+++ b/shell/gnome_control_center_completion.bash.in
@@ -0,0 +1,43 @@
+#!/bin/bash
+#
+# gnome-control-center tab completion for bash.
+
+_gnome_control_center()
+{
+	local cur prev command_list i v
+
+	cur=${COMP_WORDS[COMP_CWORD]}
+	prev=${COMP_WORDS[COMP_CWORD-1]}
+
+	case "$prev" in
+	-o|--overview)
+		command_list=""
+		;;
+	*)
+		if [ $prev = "gnome-control-center" ] ; then
+			command_list="--overview --verbose --version"
+			command_list="$command_list @PANELS@"
+		elif [ $prev = "--verbose" ]; then
+			command_list="@PANELS@"
+		fi
+
+		# FIXME
+		# Add the argvs for some of the panels that
+		# support it, such as network
+		for i in --overview --version @PANELS@; do
+			if [ $i = $prev ]; then
+				command_list=""
+			fi
+		done
+		;;
+	esac
+
+	for i in $command_list; do
+		if [ -z "${i/$cur*}" ]; then
+			COMPREPLY=( ${COMPREPLY[ ]} $i )
+		fi
+	done
+}
+
+# load the completion
+complete -F _gnome_control_center gnome-control-center
diff --git a/shell/list-panel.sh b/shell/list-panel.sh
new file mode 100755
index 0000000..070a818
--- /dev/null
+++ b/shell/list-panel.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+LIST=""
+for i in $1/panels/*/gnome-*panel.desktop.in.in ; do
+	basename=`basename $i`
+	LIST="$LIST `echo $basename | sed 's/gnome-//' | sed 's/-panel.desktop.in.in/ /'`"
+done
+echo -n $LIST



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]