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