PageRenderTime 52ms CodeModel.GetById 49ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion.d/povray

http://github.com/brinkman83/bashrc
#! | 66 lines | 61 code | 5 blank | 0 comment | 0 complexity | eb8edf39dc0f403e046628f00aa2a80f MD5 | raw file
 1# povray completion by "David Necas (Yeti)" <yeti@physics.muni.cz>
 2
 3have povray || have xpovray || have spovray &&
 4_povray()
 5{
 6    local cur prev povcur pfx oext defoext
 7    defoext=png # default output extension, if cannot be determined FIXME
 8
 9    COMPREPLY=()
10    povcur=`_get_cword`
11    prev=${COMP_WORDS[COMP_CWORD-1]}
12
13    _expand || return 0
14
15    case $povcur in
16        [-+]I*)
17            cur="${povcur#[-+]I}" # to confuse _filedir
18            pfx="${povcur%"$cur"}"
19            _filedir pov
20            COMPREPLY=( ${COMPREPLY[@]/#/$pfx} )
21            return 0
22            ;;
23        [-+]O*)
24            # guess what output file type user may want
25            case $( ( IFS=$'\n'; echo "${COMP_WORDS[*]}" | grep '^[-+]F' ) ) in
26                [-+]FN) oext=png ;;
27                [-+]FP) oext=ppm ;;
28                [-+]F[CT]) oext=tga ;;
29                *) oext=$defoext ;;
30            esac
31            # complete filename corresponding to previously specified +I
32            COMPREPLY=( $( ( IFS=$'\n'; echo "${COMP_WORDS[*]}" | grep '^[-+]I' ) ) )
33            COMPREPLY=( ${COMPREPLY[@]#[-+]I} )
34            COMPREPLY=( ${COMPREPLY[@]/%.pov/.$oext} )
35            cur="${povcur#[-+]O}" # to confuse _filedir
36            pfx="${povcur%"$cur"}"
37            _filedir $oext
38            COMPREPLY=( ${COMPREPLY[@]/#/$pfx} )
39            return 0
40            ;;
41        *.ini\[|*.ini\[*[^]]) # sections in .ini files
42            cur="${povcur#*\[}"
43            pfx="${povcur%\["$cur"}" # prefix == filename
44            [ -r "$pfx" ] || return 0
45            COMPREPLY=( $(sed -e 's/^[[:space:]]*\[\('"$cur"'[^]]*\]\).*$/\1/' \
46                -e 't' -e 'd' -- "$pfx") )
47            # to prevent [bar] expand to nothing.  can be done more easily?
48            COMPREPLY=( "${COMPREPLY[@]/#/$pfx[}" )
49            return 0
50            ;;
51        *)
52            cur="$povcur"
53            _filedir '?(ini|pov)'
54            return 0
55            ;;
56    esac
57} &&
58complete -F _povray $filenames povray xpovray spovray
59
60# Local variables:
61# mode: shell-script
62# sh-basic-offset: 4
63# sh-indent-comment: t
64# indent-tabs-mode: nil
65# End:
66# ex: ts=4 sw=4 et filetype=sh