-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathflif.bash-completion
167 lines (157 loc) · 5.51 KB
/
flif.bash-completion
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# flif(1) completion -*- shell-script -*-
_flif()
{
local cur prev words cword split
_init_completion -s || return
action=unknown
next_arg_needed=unknown
base_name=output
# scan the previous arguments to guess what we are doing: encoding or decoding?
for pw in "${words[@]:1:$((cword - 1))}"; do
case $pw in
-d|--decode)
action=decode
next_arg_needed=flif
;;
-i|--identify)
action=identify
next_arg_needed=flif
;;
-t|--transcode)
action=transcode
next_arg_needed=flif
;;
-e|--encode)
action=encode
next_arg_needed=nonflif
;;
-*)
;;
*.flif|*.flf)
case $action in
unknown|decode)
action=decode
base_name=$pw
base_name=$(basename "$base_name" .flif)
base_name=$(basename "$base_name" .flf)
case $next_arg_needed in
flif|unknown)
next_arg_needed=nonflif
;;
nonflif)
action=transcode
next_arg_needed=none
;;
esac
;;
transcode)
case $next_arg_needed in
flif)
next_arg_needed=flif2
base_name=$pw
base_name=$(basename "$base_name" .flif)
base_name=$(basename "$base_name" .flf)
base_name="$base_name-transcoded"
;;
flif2)
next_arg_needed=none
;;
esac
;;
encode)
next_arg_needed=none
;;
esac
;;
*)
case $action in
unknown|encode)
action=encode
next_arg_needed=flif
base_name=$pw
base_name=$(basename "$base_name" .png)
base_name=$(basename "$base_name" .pnm)
base_name=$(basename "$base_name" .pam)
base_name=$(basename "$base_name" .ppm)
base_name=$(basename "$base_name" .pgm)
base_name=$(basename "$base_name" .pbm)
base_name=$(basename "$base_name" .rggb)
;;
decode)
next_arg_needed=none
;;
esac
;;
esac
done
if [[ $cur != "" ]]; then
base_name=$cur
fi
case $action-$next_arg_needed in
# input file names
decode-flif|identify-flif|transcode-flif)
_filedir '@(flif|flf)'
return
;;
encode-nonflif)
_filedir '@(png|pnm|pam|ppm|pgm|pbm|rggb)'
return
;;
# suggest sensible name for output file
encode-flif)
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -vvveh )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
fi
COMPREPLY=$base_name.flif
return
;;
transcode-flif2)
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -vvvh )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
fi
COMPREPLY=$base_name.flif
return
;;
decode-nonflif)
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -vvvdh )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
fi
COMPREPLY=$base_name.png
return
;;
# no more arguments needed, suggest options
decode-none)
# only show decode options
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -vvvdh)' -- "$cur") )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
;;
encode-none)
# only show encode options
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -vvveh)' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
;;
*-none)
# show all options
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -vvvh)' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
;;
esac
$split && return 0
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -vvvh )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
fi
# suggest filenames
_filedir '@(flif|flf|png|pnm|pam|ppm|pgm|pbm|rggb)'
} &&
complete -F _flif flif