1
0

exa 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. _exa()
  2. {
  3. cur=${COMP_WORDS[COMP_CWORD]}
  4. prev=${COMP_WORDS[COMP_CWORD-1]}
  5. case "$prev" in
  6. -'?'|--help|-v|--version)
  7. return
  8. ;;
  9. --colour)
  10. COMPREPLY=( $( compgen -W 'always auto never' -- "$cur" ) )
  11. return
  12. ;;
  13. -L|--level)
  14. COMPREPLY=( $( compgen -W '{0..9}' -- "$cur" ) )
  15. return
  16. ;;
  17. -s|--sort)
  18. COMPREPLY=( $( compgen -W 'name filename Name Filename size filesize extension Extension date time modified changed accessed created type inode oldest newest age none --' -- "$cur" ) )
  19. return
  20. ;;
  21. -t|--time)
  22. COMPREPLY=( $( compgen -W 'modified changed accessed created --' -- "$cur" ) )
  23. return
  24. ;;
  25. --time-style)
  26. COMPREPLY=( $( compgen -W 'default iso long-iso full-iso relative --' -- "$cur" ) )
  27. return
  28. ;;
  29. esac
  30. case "$cur" in
  31. # _parse_help doesn’t pick up short options when they are on the same line than long options
  32. --*)
  33. # colo[u]r isn’t parsed correctly so we filter these options out and add them by hand
  34. parse_help=$( exa --help | grep -oE ' (\-\-[[:alnum:]@-]+)' | tr -d ' ' | grep -v '\-\-colo' )
  35. completions=$( echo '--color --colour --color-scale --colour-scale' $parse_help )
  36. COMPREPLY=( $( compgen -W "$completions" -- "$cur" ) )
  37. ;;
  38. -*)
  39. completions=$( exa --help | grep -oE ' (\-[[:alnum:]@])' | tr -d ' ' )
  40. COMPREPLY=( $( compgen -W "$completions" -- "$cur" ) )
  41. ;;
  42. *)
  43. _filedir
  44. ;;
  45. esac
  46. } &&
  47. complete -o filenames -o bashdefault -F _exa exa