aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bash-completion92
1 files changed, 92 insertions, 0 deletions
diff --git a/bash-completion b/bash-completion
new file mode 100644
index 0000000..c6040fc
--- /dev/null
+++ b/bash-completion
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+in_array() {
+ local i
+ for i in "${@:2}"; do
+ [[ $1 = "$i" ]] && return
+ done
+}
+
+_ponymix() {
+ local flags='-h --help -c --card -d --device -t --devtype
+ --source --input --sink --output
+ --sink-input --source-output'
+ local types='sink sink-input source source-output'
+ local verbs=(help defaults set-default list list-short
+ list-cards list-cards-short get-volume set-volume
+ get-balance set-balance adj-balance increase decrease
+ mute unmute toggle is-muted move kill
+ list-profiles list-profiles-short get-profile set-profile)
+ local i=0 cur prev verb word devtype dev idx devices
+
+ _get_comp_words_by_ref cur prev
+
+ for word in "${COMP_WORDS[@]}"; do
+ # find the verb
+ if in_array "$word" "${verbs[@]}"; then
+ verb=$word
+ break
+ fi
+
+ case $word in
+ --devtype)
+ # look ahead to next word
+ if [[ ${COMP_WORDS[i+1]} ]]; then
+ devtype=${COMP_WORDS[i+1]}
+ fi
+ ;;
+ --devtype=*)
+ devtype=${word#--devtype=}
+ ;;
+ --sink|--output)
+ devtype=sink
+ ;;
+ --source|--input)
+ devtype=source
+ ;;
+ --sink-input|--source-output)
+ devtype=${word#--}
+ ;;
+ esac
+ (( ++i ))
+ done
+
+ case $prev in
+ --card|-c)
+ mapfile -t devices < <(\ponymix list-cards-short 2>/dev/null)
+ COMPREPLY=($(compgen -W '${devices[*]}' -- "$cur"))
+ ;;
+ --device|-d)
+ while IFS=$'\t' read _ dev idx _; do
+ devices+=("$dev" "$idx")
+ done < <(\ponymix "--${devtype:-sink}" list-short 2>/dev/null)
+ COMPREPLY=($(compgen -W '${devices[*]}' -- "$cur"))
+ ;;
+ --devtype|-t)
+ COMPREPLY=($(compgen -W '$types' -- "$cur"))
+ ;;
+ esac
+ [[ $COMPREPLY ]] && return 0
+
+ case $cur in
+ -*)
+ COMPREPLY=($(compgen -W '${flags[*]}' -- "$cur"))
+ ;;
+ *)
+ [[ -z $verb ]] && COMPREPLY=($(compgen -W '${verbs[*]}' -- "$cur"))
+ ;;
+ esac
+ [[ $COMPREPLY ]] && return 0
+
+ case $word in
+ '')
+ COMPREPLY=($(compgen -W '${verbs[*]}' -- "$cur"))
+ ;;
+ esac
+
+ return 0
+}
+
+complete -F _ponymix ponymix
+
+# vim: set et ts=2 sw=2: