# povray completion -*- shell-script -*- # by "David Necas (Yeti)" proc _povray { var cur = '', prev = '', words = '', cword = '' _init_completion || return var povcur = $cur, pfx = '', oext = '', defoext = '' set defoext = 'png' # default output extension, if cannot be determined FIXME _expand || return 0 match $povcur { with [-+]I* set cur = $(povcur#[-+]I) # to confuse _filedir set pfx = $(povcur%"$cur") _filedir pov setglobal COMPREPLY = '( '${COMPREPLY[@]/#/$pfx} ) return 0 with [-+]O* # guess what output file type user may want match $[ shell { setglobal IFS = '$'\n''; command grep '^[-+]F' <<<$(words[*]) }] { with [-+]FN set oext = 'png' with [-+]FP set oext = 'ppm' with [-+]F[CT] set oext = 'tga' with * set oext = $defoext } # complete filename corresponding to previously specified +I setglobal COMPREPLY = '( '$( ( IFS=$'\n'; command grep '^[-+]I' <<<"${words[*]}" ) ) ) setglobal COMPREPLY = '( '${COMPREPLY[@]#[-+]I} ) setglobal COMPREPLY = '( '${COMPREPLY[@]/%.pov/.$oext} ) set cur = $(povcur#[-+]O) # to confuse _filedir set pfx = $(povcur%"$cur") _filedir $oext setglobal COMPREPLY = '( '${COMPREPLY[@]/#/$pfx} ) return 0 with *.ini\[|*.ini\[*[^]] # sections in .ini files set cur = $(povcur#*\[) set pfx = $(povcur%\["$cur") # prefix == filename [[ -r $pfx ]] || return 0 setglobal COMPREPLY = '( '$(sed -e 's/^[[:space:]]*\[\('"$cur"'[^]]*\]\).*$/\1/' \ -e 't' -e 'd' -- "$pfx") ) # to prevent [bar] expand to nothing. can be done more easily? setglobal COMPREPLY = '( '"${COMPREPLY[@]/#/$pfx[}" ) return 0 with * _filedir '@(ini|pov)' return 0 } } && complete -F _povray povray xpovray spovray # ex: ts=4 sw=4 et filetype=sh