blob: 868ff3eed95999d7311c70ed9809365e5dcb44a8 (
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
|
# povray completion -*- shell-script -*-
# by "David Necas (Yeti)" <yeti@physics.muni.cz>
_comp_cmd_povray()
{
local cur prev words cword comp_args
_comp_initialize -- "$@" || return
local povcur=$cur pfx oext defoext
defoext=png # default output extension, if cannot be determined FIXME
_comp_expand || return
case $povcur in
[-+]I*)
cur="${povcur#[-+]I}" # to confuse _comp_compgen_filedir
pfx="${povcur%"$cur"}"
_comp_compgen_filedir pov &&
_comp_compgen -Rv COMPREPLY -- -P "$pfx" -W '"${COMPREPLY[@]}"'
return
;;
[-+]O*)
# guess what output file type user may want
case $(
IFS=$'\n'
command grep '^[-+]F' <<<"${words[*]}"
) in
[-+]FN) oext=png ;;
[-+]FP) oext=ppm ;;
[-+]F[CT]) oext=tga ;;
*) oext=$defoext ;;
esac
# complete filename corresponding to previously specified +I
_comp_compgen -Rv COMPREPLY -- -X '![-+]I*' -W '"${words[@]}"'
_comp_compgen -Rv COMPREPLY -- -X '' -W '"${COMPREPLY[@]#[-+]I}"'
local i
for i in "${!COMPREPLY[@]}"; do
COMPREPLY[i]=${COMPREPLY[i]/%.pov/".$oext"}
done
cur="${povcur#[-+]O}" # to confuse _comp_compgen_filedir
pfx="${povcur%"$cur"}"
_comp_compgen -a filedir "$oext"
((${#COMPREPLY[@]})) &&
_comp_compgen -Rv COMPREPLY -- -P "$pfx" -W '"${COMPREPLY[@]}"'
return
;;
*.ini\[ | *.ini\[*[^]]) # sections in .ini files
cur="${povcur#*\[}"
pfx="${povcur%\["$cur"}" # prefix == filename
[[ -f $pfx && -r $pfx ]] || return
_comp_compgen_split -l -- "$(command sed -ne \
's/^[[:space:]]*\[\([^]]*\]\).*$/\1/p' -- "$pfx")" &&
# to prevent [bar] expand to nothing. can be done more easily?
_comp_compgen -Rv COMPREPLY -- -P "${pfx}[" -W '"${COMPREPLY[@]}"'
return
;;
*)
_comp_compgen_filedir '@(ini|pov)'
return
;;
esac
} &&
complete -F _comp_cmd_povray povray xpovray spovray
# ex: filetype=sh
|