theme-and-appearance.zsh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. function test-ls-args {
  21. local cmd="$1" # ls, gls, colorls, ...
  22. local args="${@[2,-1]}" # arguments except the first one
  23. command "$cmd" "$args" /dev/null &>/dev/null
  24. }
  25. # Find the option for using colors in ls, depending on the version
  26. case "$OSTYPE" in
  27. netbsd*)
  28. # On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors);
  29. # otherwise, leave ls as is, because NetBSD's ls doesn't support -G
  30. test-ls-args gls --color && alias ls='gls --color=tty'
  31. ;;
  32. openbsd*)
  33. # On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base,
  34. # with color and multibyte support) are available from ports.
  35. # `colorls` will be installed on purpose and can't be pulled in by installing
  36. # coreutils (which might be installed for ), so prefer it to `gls`.
  37. test-ls-args gls --color && alias ls='gls --color=tty'
  38. test-ls-args colorls -G && alias ls='colorls -G'
  39. ;;
  40. (darwin|freebsd)*)
  41. # This alias works by default just using $LSCOLORS
  42. test-ls-args ls -G && alias ls='ls -G'
  43. # Only use GNU ls if installed and there are user defaults for $LS_COLORS,
  44. # as the default coloring scheme is not very pretty
  45. [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] \
  46. && test-ls-args gls --color \
  47. && alias ls='gls --color=tty'
  48. ;;
  49. *)
  50. if test-ls-args ls --color; then
  51. alias ls='ls --color=tty'
  52. elif test-ls-args ls -G; then
  53. alias ls='ls -G'
  54. fi
  55. ;;
  56. esac
  57. unfunction test-ls-args
  58. # Default coloring for BSD-based ls
  59. export LSCOLORS="Gxfxcxdxbxegedabagacad"
  60. # Default coloring for GNU-based ls
  61. if [[ -z "$LS_COLORS" ]]; then
  62. # Define LS_COLORS via dircolors if available. Otherwise, set a default
  63. # equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
  64. if (( $+commands[dircolors] )); then
  65. [[ -f "$HOME/.dircolors" ]] \
  66. && source <(dircolors -b "$HOME/.dircolors") \
  67. || source <(dircolors -b)
  68. else
  69. 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"
  70. fi
  71. fi