Add tab completion file support
authorZhang Qiang <qiang.z.zhang@intel.com>
Mon, 21 Jan 2013 17:10:18 +0000 (12:10 -0500)
committerZhang Qiang <qiang.z.zhang@intel.com>
Tue, 22 Jan 2013 23:06:42 +0000 (18:06 -0500)
Change-Id: I1a122796d1374417d7e260b025303cd7223bcae4

data/gbs-completion.bash [new file with mode: 0644]
debian/rules
distfiles/gbs.spec

diff --git a/data/gbs-completion.bash b/data/gbs-completion.bash
new file mode 100644 (file)
index 0000000..152a945
--- /dev/null
@@ -0,0 +1,156 @@
+#!/bin/bash
+# copy this file to /etc/bash_completion.d/
+# or copy it to your home directory, rename it as .gbs.bash and add '. .gbs.bash' to ~/.bashrc
+
+__gbscomp ()
+{
+    local cur_="${3-$cur}"
+
+    case "$cur_" in
+        --*=)
+            COMPREPLY=()
+            ;;
+        *)
+            local IFS=$'\n'
+            COMPREPLY=($(compgen -P "${2-}"\
+                -W "$(__gbscomp_1 "${1-}" "${4-}")"\
+                -- "$cur_"))
+            ;;
+    esac
+}
+
+__gbscomp_1 ()
+{
+    local c IFS=$' \t\n'
+    for c in $1; do
+        c="$c$2"
+        case $c in
+            --*=*|*.) ;;
+            *) c="$c " ;;
+        esac
+        printf '%s\n' "$c"
+    done
+}
+
+__gbs_main ()
+{
+    COMPREPLY=()
+    local cur prev cword cfgdir=/usr/share/gbs
+    local -a words
+    if declare -F _get_comp_words_by_ref &>/dev/null ; then
+        _get_comp_words_by_ref cur prev words cword
+    else
+        cur=$2 prev=$3 words=("${COMP_WORDS[@]}") cword=$COMP_CWORD
+    fi
+
+    local i c=1 command
+    while [ $c -lt $cword ]; do
+        i="${words[c]}"
+        case "$i" in
+            --help) command="help"; break;;
+        -c) let c++ ;;
+        -*) ;;
+        *) command="$i"; break;;
+        esac
+        let c++
+    done
+
+    __gbs && return
+}
+
+__gbs_find_on_cmdline ()
+{
+    local word subcommand c=1
+    while [ $c -lt $cword ]; do
+        word="${words[c]}"
+        for subcommand in $1; do
+            if [ "$subcommand" = "$word" ]; then
+                echo "$subcommand"
+                return
+            fi
+        done
+        let c++
+    done
+}
+
+__gbs ()
+{
+    subcommands="
+        build remotebuild submit import export changelog chroot clone pull
+    "
+    common_opts="--upstream-tag= --upstream-branch= --squash-patches-until=
+        --packaging-dir= --no-patch-export"
+    lb_opts="
+        --arch= --repository= --dist= --buildroot= --clean
+        --include-all --extra-packs= --spec= --commit= --cache
+        --skip-conf-repos --profile= --noinit --keep-packs
+        --clean-repos --define
+    "
+    rb_opts="
+        --base-obsprj= --target-obsprj= --spec= --commit= --include-all
+        --status --buildlog --profile= --arch= --repository=
+    "
+    sr_opts="
+        --msg= --target= --commit= --spec= --sign --user-key= --remote= --tag=
+    "
+    im_opts="
+        --merge --upstream-branch= --author-email= --author-name= --no-pristine-tar
+        --packaging-dir= --upstream-vcs-tag= --allow-same-version --native
+        --filter=  --no-patch-import
+    "
+    ex_opts="
+        --source-rpm --include-all --commit= --spec= --outdir=
+    "
+    ch_opts="--message= --since= --packaging-dir="
+    cr_opts="--root"
+    lbex_opts="--no-configure --exclude-from-file= --exclude= --binary-list= --threads=\
+        --incremental --overwrite --clean-once --debug $lb_opts"
+    cl_opts="--upstream-branch= --all --depth="
+    pull_opts="--upstream-branch= --force --depth="
+
+    subcommand="$(__gbs_find_on_cmdline "$subcommands")"
+    if [ -z "$subcommand" ]; then
+        case  $cur in
+            --*)
+                __gbscomp "--version --help --verbose --debug"
+                ;;
+            *)
+                __gbscomp "$subcommands"
+                ;;
+        esac
+    else
+        case "${subcommand},$cur" in
+            build,--*)
+                __gbscomp "$lb_opts $lbex_opts $common_opts"
+                ;;
+            remotebuild,--*)
+                __gbscomp "$rb_opts $common_opts"
+                ;;
+            import,--*)
+                __gbscomp "$im_opts"
+                ;;
+            export,--*)
+                __gbscomp "$ex_opts $common_opts"
+                ;;
+            submit,--*)
+                __gbscomp "$sr_opts"
+                ;;
+            changelog,--*)
+                __gbscomp "$ch_opts"
+                ;;
+            chroot,--*)
+                __gbscomp "$cr_opts"
+                ;;
+            clone,--*)
+                __gbscomp "$cl_opts"
+                ;;
+            pull,--*)
+                __gbscomp "$pull_opts"
+                ;;
+            *)
+                COMPREPLY=()
+                ;;
+            esac
+    fi
+}
+complete -F __gbs_main -o bashdefault -o default -o nospace gbs
index 7e5ffc19d91b4b71e8dfc7ee07f1a22ac95bd0f1..c7bb7d134306c24283f80f642fde4b50d2742912 100644 (file)
@@ -2,6 +2,7 @@
 
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
+GBS =$(shell pwd)/debian/gbs
 build: build-stamp
 build-stamp:
        dh_testdir
@@ -19,12 +20,13 @@ install: build
        dh_clean -k
        dh_installdirs
        # Installing package
-       mkdir -p $(CURDIR)/debian/gbs $(CURDIR)/debian/gbs/usr/bin $(CURDIR)/debian/gbs/usr/share/doc/gbs
-       install -m644 docs/RELEASE_NOTES $(CURDIR)/debian/gbs/usr/share/doc/gbs
-       #make DESTDIR=$(CURDIR)/debian/gbs installman
-       #make DESTDIR=$(CURDIR)/debian/gbs installconf
-       #make DESTDIR=$(CURDIR)/debian/gbs installsymlinks
-       python setup.py install --root=$(CURDIR)/debian/gbs --prefix=/usr --install-layout=deb
+       mkdir -p '$(GBS)' '$(GBS)'/usr/bin '$(GBS)'/usr/share/doc/gbs
+       install -m644 docs/RELEASE_NOTES '$(GBS)'/usr/share/doc/gbs
+       # Bash completion
+       install -d -m0755 '$(GBS)'/etc/bash_completion.d
+       install -m0644 data/gbs-completion.bash \
+         '$(GBS)'/etc/bash_completion.d/gbs
+       python setup.py install --root=$(GBS) --prefix=/usr --install-layout=deb
 
 binary-indep: build install
        dh_testdir
index 5042f9fe1a1b784a9660efa9d1a8caa1ea8e0a66..0c9145e81c6fcc4f9ebf4f2f472eee43cef05522 100644 (file)
@@ -40,6 +40,8 @@ rm -rf $RPM_BUILD_ROOT
 %else
 %{__python} setup.py install --root=$RPM_BUILD_ROOT -O1
 %endif
+mkdir -p %{buildroot}%{_sysconfdir}/bash_completion.d
+install -pm 644 data/gbs-completion.bash %{buildroot}%{_sysconfdir}/bash_completion.d/gbs
 
 #mkdir -p %{buildroot}/%{_prefix}/share/man/man1
 #install -m644 doc/gbs.1 %{buildroot}/%{_prefix}/share/man/man1
@@ -52,3 +54,4 @@ rm -rf $RPM_BUILD_ROOT
 %dir %{_datadir}/%{name}
 %{_datadir}/%{name}/*
 %{_bindir}/*
+%{_sysconfdir}/bash_completion.d