diff options
Diffstat (limited to 'etc/bash_completion.d')
-rw-r--r-- | etc/bash_completion.d/youri | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/etc/bash_completion.d/youri b/etc/bash_completion.d/youri new file mode 100644 index 0000000..55e285d --- /dev/null +++ b/etc/bash_completion.d/youri @@ -0,0 +1,141 @@ +# youri tools completion +# $Id$ + +_youri-check() +{ + + local cur prev config i mode + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --config) + _filedir + return 0 + ;; + --skip-plugin) + _find_config check.conf + if [ -n "$config" ]; then + # try to guess mode + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" != -* ]]; then + mode=${COMP_WORDS[i]} + break + fi + done + + if [ -n $mode ]; then + COMPREPLY=( $( awk -F= '/^'$mode's/ {print $2}' $config \ + | grep "^$cur" ) ) + fi + fi + return 0 + ;; + --skip-media) + _find_config check.conf + if [ -n "$config" ]; then + COMPREPLY=( $( awk -F= '/^medias/ {print $2}' $config \ + | grep "^$cur" ) ) + fi + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--config --skip-plugin --skip-media -h \ + --help -t --test -v --verbose' -- $cur ) ) + else + _count_args + case $args in + 1) + COMPREPLY=( $( compgen -W 'input output' -- $cur ) ) + ;; + esac + fi + +} +complete -F _youri-check youri-check + +_youri-upload() +{ + + local cur prev config + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + case "$prev" in + --config) + _filedir + return 0 + ;; + --skip-check) + _find_config upload.conf + if [ -n "$config" ]; then + COMPREPLY=( $( awk -F= '/^checks/ {print $2}' $config \ + | grep "^$cur" ) ) + fi + return 0 + ;; + --skip-action) + _find_config upload.conf + if [ -n "$config" ]; then + COMPREPLY=( $( awk -F= '/^actions/ {print $2}' $config \ + | grep "^$cur" ) ) + fi + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '--config --skip-check --skip-action \ + --define -h --help -t --test -v --verbose' -- $cur ) ) + else + _count_args + case $args in + 1) + _find_config upload.conf + if [ -n "$config" ]; then + COMPREPLY=( $( awk -F= '/^targets/ {print $2}' $config \ + | grep "^$cur" ) ) + fi + ;; + *) + _filedir + ;; + esac + fi + +} +complete -F _youri-upload youri-upload + +_find_config() +{ + local name i + + name=$1 + + for (( i=1; i < COMP_CWORD; i++ )); do + if [[ "${COMP_WORDS[i]}" == --config ]]; then + config=${COMP_WORDS[i+1]} + break + fi + done + if [ -f "$config" ]; then + return 0 + fi + + if [ -f "$HOME/.youri/$name" ]; then + config=$HOME/.youri/$name + return 0 + fi + + if [ -f "/etc/youri/$name" ]; then + config=/etc/youri/$name + return 0 + fi + +} |