theme-and-appearance.zsh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Sets color variable such as $fg, $bg, $color and $reset_color
  2. autoload -U colors && colors
  3. # Expand variables and commands in PROMPT variables
  4. setopt prompt_subst
  5. # Prompt function theming defaults
  6. ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Beginning of the git prompt, before the branch name
  7. ZSH_THEME_GIT_PROMPT_SUFFIX=")" # End of the git prompt
  8. ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
  9. ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
  10. ZSH_THEME_RUBY_PROMPT_PREFIX="("
  11. ZSH_THEME_RUBY_PROMPT_SUFFIX=")"
  12. # Use diff --color if available
  13. if command diff --color /dev/null{,} &>/dev/null; then
  14. function diff {
  15. command diff --color "$@"
  16. }
  17. fi
  18. # Don't set ls coloring if disabled
  19. [[ "$DISABLE_LS_COLORS" != true ]] || return 0
  20. # Default coloring for BSD-based ls
  21. export LSCOLORS="Gxfxcxdxbxegedabagacad"
  22. # Default coloring for GNU-based ls
  23. if [[ -z "$LS_COLORS" ]]; then
  24. # Define LS_COLORS via dircolors if available. Otherwise, set a default
  25. # equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
  26. if (( $+commands[dircolors] )); then
  27. [[ -f "$HOME/.dircolors" ]] \
  28. && source <(dircolors -b "$HOME/.dircolors") \
  29. || source <(dircolors -b)
  30. else
  31. export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
  32. fi
  33. fi
  34. function test-ls-args {
  35. local cmd="$1" # ls, gls, colorls, ...
  36. local args="${@[2,-1]}" # arguments except the first one
  37. command "$cmd" "$args" /dev/null &>/dev/null
  38. }
  39. # Find the option for using colors in ls, depending on the version
  40. case "$OSTYPE" in
  41. netbsd*)
  42. # On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors);
  43. # otherwise, leave ls as is, because NetBSD's ls doesn't support -G
  44. test-ls-args gls --color && alias ls='gls --color=tty'
  45. ;;
  46. openbsd*)
  47. # On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base,
  48. # with color and multibyte support) are available from ports.
  49. # `colorls` will be installed on purpose and can't be pulled in by installing
  50. # coreutils (which might be installed for ), so prefer it to `gls`.
  51. test-ls-args gls --color && alias ls='gls --color=tty'
  52. test-ls-args colorls -G && alias ls='colorls -G'
  53. ;;
  54. (darwin|freebsd)*)
  55. # This alias works by default just using $LSCOLORS
  56. test-ls-args ls -G && alias ls='ls -G'
  57. # Only use GNU ls if installed and there are user defaults for $LS_COLORS,
  58. # as the default coloring scheme is not very pretty
  59. zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \
  60. && test-ls-args gls --color \
  61. && alias ls='gls --color=tty'
  62. ;;
  63. *)
  64. if test-ls-args ls --color; then
  65. alias ls='ls --color=tty'
  66. elif test-ls-args ls -G; then
  67. alias ls='ls -G'
  68. fi
  69. ;;
  70. esac
  71. unfunction test-ls-args