Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--shell/bash-completion61
2 files changed, 67 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 2512cc7..2a2798c 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,9 @@ BINPROGS = \
MANPAGES = \
man/asp.1
+BASH_COMPLETION = \
+ shell/bash-completion
+
INCLUDES = \
package.inc.sh \
remote.inc.sh \
@@ -36,9 +39,9 @@ clean:
$(RM) $(BINPROGS) $(MANPAGES)
install: all
- install -dm755 $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/share/man/man1
- install -m755 $(BINPROGS) $(DESTDIR)$(PREFIX)/bin
- install -m644 $(MANPAGES) $(DESTDIR)$(PREFIX)/share/man/man1
+ install -Dm755 $(BINPROGS) $(DESTDIR)$(PREFIX)/bin
+ install -Dm644 $(MANPAGES) $(DESTDIR)$(PREFIX)/share/man/man1
+ install -Dm644 $(BASH_COMPLETION) $(DESTDIR)$(PREFIX)/share/bash-completion/completions/asp
dist:
git archive --format=tar --prefix=$(PACKAGE_NAME)-$(VER)/ v$(VER) | gzip -9 > $(PACKAGE_NAME)-$(VER).tar.gz
diff --git a/shell/bash-completion b/shell/bash-completion
new file mode 100644
index 0000000..b59be7e
--- /dev/null
+++ b/shell/bash-completion
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+in_array() {
+ for _ in "${@:2}"; do
+ [[ $_ = "$1" ]] && return 0
+ done
+ return 1
+}
+
+_asp() {
+ local a= cur= prev= comps=
+
+ _get_comp_words_by_ref cur prev
+
+ # top level commands
+ local -A verbs=(
+ [ALL_PACKAGES]='checkout difflog export list-arches list-repos log shortlog'
+ [LOCAL_PACKAGES]='untrack update'
+ [NONE]='disk-usage gc help list-all'
+ )
+
+ # flags
+ local -A opts=(
+ [UNKNOWN]='-a'
+ [NONE]='-f -h -V'
+ )
+
+ if in_array "$prev" ${opts[UNKNOWN]}; then
+ return 0
+ fi
+
+ if [[ $cur = -* ]]; then
+ COMPREPLY=( $(compgen -W '${opts[*]}' -- "$cur") )
+ return 0
+ fi
+
+ for word in "${COMP_WORDS[@]}"; do
+ if in_array "$word" ${verbs[ALL_PACKAGES]}; then
+ a=$word
+ comps=$(\asp list-all | sed 's,.*/,,')
+ break
+ elif in_array "$word" ${verbs[LOCAL_PACKAGES]}; then
+ a=$word
+ comps=$(\asp list-local | sed 's,.*/,,')
+ break
+ elif in_array "$word" ${verbs[NONE]}; then
+ a=$word
+ break
+ fi
+ done
+
+ if [[ -z $a ]]; then
+ comps=${verbs[*]}
+ fi
+
+ if [[ $comps ]]; then
+ COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+ fi
+}
+
+complete -F _asp asp