Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2014-08-16 21:18:25 -0400
committerDave Reisner <dreisner@archlinux.org>2014-08-16 21:18:25 -0400
commit5e640c2534a287210f83dfb492dbe9a37b895a39 (patch)
treec68fa09dbf7c458ad3b6057f667f5dd547881be2 /shell
parent9b3fc65b80bb82016cd51c9bc5327a472a25a525 (diff)
add bash-completion
Diffstat (limited to 'shell')
-rw-r--r--shell/bash-completion61
1 files changed, 61 insertions, 0 deletions
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