aboutsummaryrefslogtreecommitdiffstats
path: root/etc/bash_completion.d/youri
blob: 55e285db28493fc754353ba405c16e3d91efc452 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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

}