Skip to contentSkip to conversation

xl:Add basic bash completion for xl command

PATCH In review Yang Hongyang 1 participant 3 messages Apr 27, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xl:Add basic bash completion for xl command

Add basic bash completion for xl command.

Config.mk +1 -0
diff -r c87ec146229a Config.mk
@@ -19,6 +19,7 @@
 
 DISTDIR     ?= $(XEN_ROOT)/dist
 DESTDIR     ?= /
+BASH_COMPLETION_DIR ?= /etc/profile.d
 
 # Allow phony attribute to be listed as dependency rather than fake target
 .PHONY: .phony
tools/libxl/Makefile +1 -0
diff -r c87ec146229a tools/libxl/Makefile
@@ -85,6 +85,7 @@
 	ln -sf libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(LIBDIR)/libxlutil.so
 	$(INSTALL_DATA) libxlutil.a $(DESTDIR)$(LIBDIR)
 	$(INSTALL_DATA) libxl.h $(DESTDIR)$(INCLUDEDIR)
+	$(INSTALL_DATA) bash-completion $(BASH_COMPLETION_DIR)/xl.sh
 
 .PHONY: clean
 clean:
tools/libxl/bash-completion new file +17 -0
diff -r c87ec146229a tools/libxl/bash-completion
@@ -0,0 +1,17 @@
+#!/bin/bash
+# Copy this file to /etc/profile.d/xl.sh
+
+_xl()
+{
+	local cur opts xl
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	xl=xl
+	
+	if [[ $COMP_CWORD == 1 ]] ; then
+		opts=`${xl} help 2>/dev/null | sed 'n;d' | sed '1,2d' | awk '{print $1}' | sed 's/$/ ,/g'` && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+		return 0
+	fi
+}
+
+complete -F _xl -o nospace xl
Signature · 2 lines
Regards
Yang Hongyang
#1 lore raw

Add basic bash completion for xl command.

Config.mk +1 -0
diff -r c87ec146229a Config.mk
@@ -19,6 +19,7 @@
 
 DISTDIR     ?= $(XEN_ROOT)/dist
 DESTDIR     ?= /
+BASH_COMPLETION_DIR ?= /etc/profile.d
 
 # Allow phony attribute to be listed as dependency rather than fake target
 .PHONY: .phony
tools/libxl/Makefile +1 -0
diff -r c87ec146229a tools/libxl/Makefile
@@ -85,6 +85,7 @@
 	ln -sf libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(LIBDIR)/libxlutil.so
 	$(INSTALL_DATA) libxlutil.a $(DESTDIR)$(LIBDIR)
 	$(INSTALL_DATA) libxl.h $(DESTDIR)$(INCLUDEDIR)
+	$(INSTALL_DATA) bash-completion $(BASH_COMPLETION_DIR)/xl.sh
 
 .PHONY: clean
 clean:
tools/libxl/bash-completion new file +19 -0
diff -r c87ec146229a tools/libxl/bash-completion
@@ -0,0 +1,19 @@
+#!/bin/bash
+# Copy this file to /etc/profile.d/xl.sh
+
+_xl()
+{
+	local IFS=$'\n,'
+
+	local cur opts xl
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	xl=xl
+	
+	if [[ $COMP_CWORD == 1 ]] ; then
+		opts=`${xl} help 2>/dev/null | sed 'n;d' | sed '1,2d' | awk '{print $1}' | sed 's/$/ ,/g'` && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+		return 0
+	fi
+}
+
+complete -F _xl -o nospace xl
Signature · 2 lines
Regards
Yang Hongyang
#2 lore raw

v2->v3
If no matchs found,fallback to default completion.

====================================================================

Add basic bash completion for xl command.

Config.mk +1 -0
diff -r c87ec146229a Config.mk
@@ -19,6 +19,7 @@
 
 DISTDIR     ?= $(XEN_ROOT)/dist
 DESTDIR     ?= /
+BASH_COMPLETION_DIR ?= /etc/profile.d
 
 # Allow phony attribute to be listed as dependency rather than fake target
 .PHONY: .phony
tools/libxl/Makefile +1 -0
diff -r c87ec146229a tools/libxl/Makefile
@@ -85,6 +85,7 @@
 	ln -sf libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(LIBDIR)/libxlutil.so
 	$(INSTALL_DATA) libxlutil.a $(DESTDIR)$(LIBDIR)
 	$(INSTALL_DATA) libxl.h $(DESTDIR)$(INCLUDEDIR)
+	$(INSTALL_DATA) bash-completion $(BASH_COMPLETION_DIR)/xl.sh
 
 .PHONY: clean
 clean:
tools/libxl/bash-completion new file +21 -0
diff -r c87ec146229a tools/libxl/bash-completion
@@ -0,0 +1,21 @@
+#!/bin/bash
+# Copy this file to /etc/profile.d/xl.sh
+
+_xl()
+{
+	local IFS=$'\n,'
+
+	local cur opts xl
+	COMPREPLY=()
+	cur="${COMP_WORDS[COMP_CWORD]}"
+	xl=xl
+	
+	if [[ $COMP_CWORD == 1 ]] ; then
+		opts=`${xl} help 2>/dev/null | sed 'n;d' | sed '1,2d' | awk '{print $1}' | sed 's/$/ ,/g'` && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+		return 0
+	fi
+
+	return 0
+}
+
+complete -F _xl -o nospace -o default xl
Signature · 2 lines
Regards
Yang Hongyang