eza 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # shellcheck shell=bash
  2. _eza() {
  3. cur=${COMP_WORDS[COMP_CWORD]}
  4. prev=${COMP_WORDS[COMP_CWORD-1]}
  5. case "$prev" in
  6. --help|-v|--version|--smart-group)
  7. return
  8. ;;
  9. --colour)
  10. mapfile -t COMPREPLY < <(compgen -W 'always automatic auto never' -- "$cur")
  11. return
  12. ;;
  13. -L|--level)
  14. mapfile -t COMPREPLY < <(compgen -W '{0..9}' -- "$cur")
  15. return
  16. ;;
  17. -s|--sort)
  18. mapfile -t 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. mapfile -t COMPREPLY < <(compgen -W 'modified changed accessed created --' -- "$cur")
  23. return
  24. ;;
  25. --time-style)
  26. mapfile -t 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=$(eza --help | grep -oE ' (--[[:alnum:]@-]+)' | tr -d ' ' | grep -v '\--colo')
  35. completions=$(echo '--color --colour --color-scale --colour-scale' "$parse_help")
  36. mapfile -t COMPREPLY < <(compgen -W "$completions" -- "$cur")
  37. ;;
  38. -*)
  39. completions=$(eza --help | grep -oE ' (-[[:alnum:]@])' | tr -d ' ')
  40. mapfile -t COMPREPLY < <(compgen -W "$completions" -- "$cur")
  41. ;;
  42. *)
  43. _filedir
  44. ;;
  45. esac
  46. } &&
  47. complete -o filenames -o bashdefault -F _eza eza