Parent directory

theme-and-appearance.zsh

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