Browse Source

added vbuilder-bash-completion.sh

git-svn-id: http://trac.vinelinux.org/repos/projects/vbootstrap/trunk@484 ec354946-7b23-47d6-9f5a-488ba84defc7
munepi 14 years ago
parent
commit
f27dc3a9bb
3 changed files with 88 additions and 1 deletions
  1. 2 0
      Makefile
  2. 5 1
      vbootstrap.spec
  3. 81 0
      vbuilder-bash-completion.sh

+ 2 - 0
Makefile

@@ -24,11 +24,13 @@ install:
 	install -d ${DESTDIR}/usr/share/vbootstrap/{scripts,sources.list.d}
 	install -d ${DESTDIR}/usr/sbin
 	install -d ${DESTDIR}/etc/vbootstrap
+	install -d ${DESTDIR}/etc/bash_completion.d
 	install -m 644 vbootstrap/scripts/* ${DESTDIR}/usr/share/vbootstrap/scripts/
 	install -m 644 vbootstrap/sources.list.d/* ${DESTDIR}/usr/share/vbootstrap/sources.list.d
 	install -m 755 vbootstrap.sh ${DESTDIR}/usr/sbin/vbootstrap
 	install -m 755 vbuilder.sh ${DESTDIR}/usr/sbin/vbuilder
 	install -m 644 vbuilder.conf ${DESTDIR}/etc/vbootstrap/vbuilder.conf
+	install -m 644 vbuilder-bash-completion.sh ${DESTDIR}/etc/bash_completion.d/vbuilder
 
 tarbz2: clean
 	cd .. && rm -rf ${NAME}-${VERSION}

+ 5 - 1
vbootstrap.spec

@@ -1,7 +1,7 @@
 # This package is maintained on trac svn repository. Please do not change on local.
 # If you find a BUG, please report to Vine@vinelinux.org or mailing list or BTS.
 
-%define version 0.0.14
+%define version 0.0.15
 
 Summary: bootstrap scripts to create a basic Vine Linux system
 Summary(ja): Vine Linux の基本システムを作成するためのスクリプト
@@ -55,10 +55,14 @@ make DESTDIR=$RPM_BUILD_ROOT install
 %{_sbindir}/vbuilder
 %dir %{_datadir}/vbootstrap
 %{_datadir}/vbootstrap/*
+%{_sysconfdir}/bash_completion.d/vbuilder
 %config(noreplace) %{_sysconfdir}/vbootstrap/vbuilder.conf
 
 
 %changelog
+* Sat Feb 20 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.0.15-1
+- added vbuilder-bash-completion.sh
+
 * Sat Feb 13 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.0.14-1
 - updated vbuilder.sh.in
   - used __chroot_sh

+ 81 - 0
vbuilder-bash-completion.sh

@@ -0,0 +1,81 @@
+[ -z "$BASH_VERSION" ] && return
+
+_filedir()
+{
+	local IFS=$'\t\n' xspec #glob
+
+	#glob=$(set +o|grep noglob) # save glob setting.
+	#set -f		 # disable pathname expansion (globbing)
+
+	xspec=${1:+"!*.$1"}	# set only if glob passed in as $1
+	COMPREPLY=( ${COMPREPLY[@]:-} $( compgen -f -X "$xspec" -- "$cur" ) \
+		    $( compgen -d -- "$cur" ) )
+	#eval "$glob"    # restore glob setting.
+}
+
+_vbuilder()
+{
+    local opts cur prev first
+    COMPREPLY=()
+    cur="${COMP_WORDS[COMP_CWORD]}"
+    prev="${COMP_WORDS[COMP_CWORD-1]}"
+    first="${COMP_WORDS[1]}"
+
+    ## The basic options we'll complete.
+    options="--version --arch --dist-upgrade --target --with-compat32"
+    actions="--clean --build --build-rpm --install-rpm --remove-rpm"
+    opts="$options $actions"
+
+    _arch=$(rpm --eval %_arch)
+
+    in_options=0
+
+    ## Complete the arguments to some of the basic commands.
+    case "${prev}" in
+	--version)
+	    if [ "$_arch" = "x86_64" ]; then
+		local running="VineSeed VineSeed_i386 5.0 5.0_i386 4.2_i386"
+	    else
+		local running="VineSeed 5.0 4.2"
+	    fi
+	    COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
+	    ;;
+
+	--arch)
+	    local running="i386 ppc x86_64"
+	    COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
+	    ;;
+
+	--target)
+	    local running="$(cat /usr/lib/rpm/rpmrc | grep arch_canon: | sed -e "s/arch_canon:[[:blank:]]*\(.*\):.*/\1/")"
+	    COMPREPLY=( $(compgen -W "${running}" -- "${cur}") )
+	    ;;
+
+	--build-rpm)
+	    if [ $COMP_CWORD -eq 1 -o "${COMPREPLY+set}" != "set" ]; then
+		_filedir 'src.rpm'
+	    fi
+	    ;;
+
+	--install-rpm|--remove-rpm)
+	    if [ $COMP_CWORD -eq 1 -o "${COMPREPLY+set}" != "set" ]; then
+		_filedir 'rpm'
+	    fi
+	    ;;
+
+	*)
+	    COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
+	    #return 0
+	    ;;
+    esac
+
+    if [[ "${cur}" == -* ]] ; then
+    	COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
+    	#return 0
+    fi
+
+}
+
+complete -o filenames -o nospace -F _vbuilder vbuilder
+
+### end of file