diff options
Diffstat (limited to 'completions/povray')
-rw-r--r-- | completions/povray | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/completions/povray b/completions/povray index 56dfd94..868ff3e 100644 --- a/completions/povray +++ b/completions/povray @@ -1,22 +1,22 @@ # povray completion -*- shell-script -*- # by "David Necas (Yeti)" <yeti@physics.muni.cz> -_povray() +_comp_cmd_povray() { - local cur prev words cword - _init_completion || return + 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 - _expand || return + _comp_expand || return case $povcur in [-+]I*) - cur="${povcur#[-+]I}" # to confuse _filedir + cur="${povcur#[-+]I}" # to confuse _comp_compgen_filedir pfx="${povcur%"$cur"}" - _filedir pov - COMPREPLY=(${COMPREPLY[@]/#/$pfx}) + _comp_compgen_filedir pov && + _comp_compgen -Rv COMPREPLY -- -P "$pfx" -W '"${COMPREPLY[@]}"' return ;; [-+]O*) @@ -31,34 +31,35 @@ _povray() *) oext=$defoext ;; esac # complete filename corresponding to previously specified +I - COMPREPLY=($( - IFS=$'\n' - command grep '^[-+]I' <<<"${words[*]}" - )) - COMPREPLY=(${COMPREPLY[@]#[-+]I}) - COMPREPLY=(${COMPREPLY[@]/%.pov/.$oext}) - cur="${povcur#[-+]O}" # to confuse _filedir + _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"}" - _filedir $oext - COMPREPLY=(${COMPREPLY[@]/#/$pfx}) + _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 - [[ -r $pfx ]] || return - COMPREPLY=($(command sed -e 's/^[[:space:]]*\[\('"$cur"'[^]]*\]\).*$/\1/' \ - -e 't' -e 'd' -- "$pfx")) - # to prevent [bar] expand to nothing. can be done more easily? - COMPREPLY=("${COMPREPLY[@]/#/${pfx}[}") + [[ -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 ;; *) - _filedir '@(ini|pov)' + _comp_compgen_filedir '@(ini|pov)' return ;; esac } && - complete -F _povray povray xpovray spovray + complete -F _comp_cmd_povray povray xpovray spovray # ex: filetype=sh |