/bash_completion_lib/include/_longopt

http://github.com/brinkman83/bashrc · #! · 29 lines · 24 code · 5 blank · 0 comment · 0 complexity · 03becb8469cfbf19f57a3c4a99eee3b6 MD5 · raw file

  1. comp_include _filedir _get_cword
  2. _longopt()
  3. {
  4. local cur opt
  5. cur=`_get_cword`
  6. if [[ "$cur" == --*=* ]]; then
  7. opt=${cur%%=*}
  8. # cut backslash that gets inserted before '=' sign
  9. opt=${opt%\\*}
  10. cur=${cur#*=}
  11. _filedir
  12. COMPREPLY=( $( compgen -P "$opt=" -W '${COMPREPLY[@]}' -- $cur))
  13. return 0
  14. fi
  15. if [[ "$cur" == -* ]]; then
  16. COMPREPLY=( $( $1 --help 2>&1 | sed -e '/--/!d' \
  17. -e 's/.*\(--[-A-Za-z0-9]\+=\?\).*/\1/' | \
  18. command grep "^$cur" | sort -u ) )
  19. elif [[ "$1" == @(mk|rm)dir ]]; then
  20. _filedir -d
  21. else
  22. _filedir
  23. fi
  24. }