eza 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. --icons)
  14. mapfile -t COMPREPLY < <(compgen -W 'always automatic auto never' -- "$cur")
  15. return
  16. ;;
  17. -L|--level)
  18. mapfile -t COMPREPLY < <(compgen -W '{0..9}' -- "$cur")
  19. return
  20. ;;
  21. -s|--sort)
  22. 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")
  23. return
  24. ;;
  25. -t|--time)
  26. mapfile -t COMPREPLY < <(compgen -W 'modified changed accessed created --' -- "$cur")
  27. return
  28. ;;
  29. --time-style)
  30. mapfile -t COMPREPLY < <(compgen -W 'default iso long-iso full-iso relative --' -- "$cur")
  31. return
  32. ;;
  33. esac
  34. case "$cur" in
  35. # _parse_help doesn’t pick up short options when they are on the same line than long options
  36. --*)
  37. # colo[u]r isn’t parsed correctly so we filter these options out and add them by hand
  38. parse_help=$(eza --help | grep -oE ' (--[[:alnum:]@-]+)' | tr -d ' ' | grep -v '\--colo')
  39. completions=$(echo '--color --colour --color-scale --colour-scale' "$parse_help")
  40. mapfile -t COMPREPLY < <(compgen -W "$completions" -- "$cur")
  41. ;;
  42. -*)
  43. completions=$(eza --help | grep -oE ' (-[[:alnum:]@])' | tr -d ' ')
  44. mapfile -t COMPREPLY < <(compgen -W "$completions" -- "$cur")
  45. ;;
  46. *)
  47. _filedir
  48. ;;
  49. esac
  50. } &&
  51. complete -o filenames -o bashdefault -F _eza eza