zsh: Update zshrc and starship configs
[shutils.git] / dotfiles / shell / .zshrc
1 # sample by Peter Palfrader: http://svn.noreply.org/svn/weaselutils/trunk/dotfiles/zshrc
2
3 [ -r /etc/zsh/zprofile ] && source /etc/zsh/zprofile
4 [ -r $HOME/.profile ] && source $HOME/.profile
5
6
7 bindkey -e
8 zstyle :compinstall filename "$HOME/.zshrc"
9
10
11 autoload -U compinit promptinit
12 compinit
13 zstyle ':completion::complete:*' use-cache 1
14
15 autoload colors zsh/terminfo
16 if [[ "$terminfo[colors]" -ge 8 ]]; then
17 colors
18 fi
19
20 eval `dircolors`
21 LS_COLORS="${LS_COLORS}*.divx=01;35:"
22 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
23
24 zstyle ':completion:*' menu select
25 zmodload -i zsh/complist
26
27 # bind special keys according to readline configuration
28 #eval "$(sed -n 's/^/bindkey /; s/: / /p' /etc/inputrc)"
29
30 bindkey "\e[1~" beginning-of-line
31 bindkey "\e[4~" end-of-line
32 bindkey "\e[5~" history-search-backward
33 bindkey "\e[6~" history-search-forward
34 bindkey "\e[3~" delete-char
35 bindkey "\e[2~" quoted-insert
36 bindkey "\e[5C" forward-word
37 bindkey "\e[5D" backward-word
38 bindkey "\e\e[C" forward-word
39 bindkey "\e\e[D" backward-word
40 bindkey "\e[1;5C" forward-word
41 bindkey "\e[1;5D" backward-word
42 bindkey "\eOc" forward-word
43 bindkey "\eOd" backward-word
44 bindkey "\e[1;3C" forward-word
45 bindkey "\e[1;3D" backward-word
46 bindkey "\e[8~" end-of-line
47 bindkey "\eOH" beginning-of-line
48 bindkey "\eOF" end-of-line
49 bindkey "\e[H" beginning-of-line
50 bindkey "\e[F" end-of-line
51 bindkey "\e[7~" beginning-of-line
52 bindkey "\e[8~" end-of-line
53
54
55
56 setopt \
57 EXTENDEDGLOB \
58 BASH_AUTO_LIST \
59 LIST_AMBIGUOUS \
60 CHECK_JOBS \
61 INC_APPEND_HISTORY \
62 HIST_IGNORE_DUPS \
63 HIST_IGNORE_SPACE \
64 NO_HUP
65
66
67 HISTFILE=~/.zsh_history
68 HISTSIZE=50000
69 SAVEHIST=50000
70 REPORTTIME=5
71 TIMEFMT="$fg[magenta]%J %U user %S sys %P cpu %*E total %M MB RSS max$terminfo[sgr0]"
72
73
74 # Load starship if exists, and that's it.
75 #if [ $TERM != "linux" ] && type "starship" > /dev/null; then
76 eval "$(starship init zsh)"
77 return
78 #fi
79
80
81 # Otherwise, do some homebrewn configuration
82
83 autoload -Uz vcs_info && vcs_info
84 zstyle ':vcs_info:*' enable git cvs svn hg
85 zstyle ':vcs_info:*' use-prompt-escapes
86 zstyle ':vcs_info:*' max-exports 1
87
88
89 function setprompt()
90 {
91 # default: " (%s)-[%b|%a]%u%c-"
92 zstyle ':vcs_info:*' actionformats " %s: %b|%a"
93 # default: " (%s)-[%b]%u%c-"
94 zstyle ':vcs_info:*' formats " %s: %b"
95
96 setopt PROMPT_SUBST
97 PROMPT='
98 %(!.%{$fg_bold[red]%}.%{$fg_bold[green]%})%n@%m%{$reset_color%}$PR_SCREEN$PR_JOBS%{$fg_bold[yellow]%}${vcs_info_msg_0_}%{$reset_color%} %{$fg_bold[blue]%}%~%{$reset_color%}
99 $PR_EXIT%# '
100 }
101 setprompt
102
103 # Obtain the autofs mountpoints
104 autofs_mp=()
105 [ -r /etc/auto.master ] && autofs_mp=($(/bin/grep -e "^/" /etc/auto.master | cut -f1))
106
107 function precmd ()
108 {
109 PR_EXIT="%{$fg_bold[red]%}%(?..[%?] )%{$reset_color%}"
110
111 # Check whether current directory is a subdirectory of an autofs mountpoint
112 local parent="0"
113 vcs_info_msg_0_=""
114 for mp in ${autofs_mp}; do
115 # A parent directory is an autofs mount point
116 if echo "$PWD" | /bin/grep -q $mp; then
117 parent="1"
118 # Even equal!
119 if echo "$mp" | /bin/grep -q $PWD; then
120 vcs_info_msg_0_=" [autofs]"
121 fi
122 break;
123 fi
124 done
125
126 if [ -z "$vcs_info_msg_0_" ]; then
127 if [ "$parent" = "1" ]; then
128 # svn and hg cause complaints of autofs that .svn and .hg is no mount point
129 zstyle ':vcs_info:*' enable git cvs
130 else
131 zstyle ':vcs_info:*' enable git cvs svn hg
132 fi
133 vcs_info
134 fi
135
136 PR_SCREEN=""
137 if [[ -n "${WINDOW}" ]]; then
138 PR_SCREEN=" S:${WINDOW}"
139 fi
140
141 PR_JOBS=""
142 if [[ $(jobs | wc -l) -gt 0 ]]; then
143 PR_JOBS=" J:%j"
144 fi
145
146 }