]>
Commit | Line | Data |
---|---|---|
3c83c67b | 1 | ### options |
2 | setopt NO_BEEP NO_CLOBBER | |
3 | ## cd | |
4 | setopt AUTO_CD CDABLE_VARS | |
5 | ## completion | |
6 | setopt GLOB_COMPLETE | |
7 | ## line | |
8 | setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT | |
9 | ## prompt | |
10 | setopt PROMPT_SUBST | |
11 | ## jobs | |
12 | setopt AUTO_CONTINUE | |
13 | ## history | |
73492710 | 14 | setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY HIST_REDUCE_BLANKS |
3c83c67b | 15 | |
16 | ### keys | |
17 | # TODO: investigate "^[[200~" bracketed-paste | |
18 | bindkey -v | |
19 | KEYTIMEOUT=10 | |
20 | ## populate key array | |
21 | if (( $#terminfo == 0 )) { | |
22 | # terminfo is not set or empty | |
23 | function find_keymap { | |
24 | for f in ${ZDOTDIR:-$HOME}/.zkbd/${TERM}{-${DISPLAY:-${VENDOR}-${OSTYPE}},} | |
25 | [[ -f $f ]] && keymap=$f && break | |
26 | } | |
27 | find_keymap | |
28 | if [[ -z $keymap ]] { | |
29 | if read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]"; then | |
30 | echo | |
31 | autoload -Uz zkbd && zkbd | |
32 | unfunction zkbd | |
33 | find_keymap | |
34 | fi | |
35 | echo | |
36 | } | |
37 | if [[ -n $keymap ]] { | |
38 | source $keymap | |
39 | } else { | |
f11fbf9e | 40 | echo "Failed to source keymap file $keymap" >&2 |
3c83c67b | 41 | } |
42 | unfunction find_keymap; unset keymap | |
43 | } else { | |
44 | # activate application mode for zle so terminfo keys work | |
f11fbf9e | 45 | # NOTE: don't do this for zkbd since application mode shouldn't have been |
46 | # enabled by zkbd when the keymap file was generated | |
3c83c67b | 47 | if [[ -v terminfo[smkx] && -v terminfo[rmkx] ]] { |
48 | autoload -Uz add-zle-hook-widget | |
49 | function _enter-application-mode { echoti smkx } | |
50 | add-zle-hook-widget line-init _enter-application-mode | |
51 | function _exit-application-mode { echoti rmkx } | |
52 | add-zle-hook-widget line-finish _exit-application-mode | |
53 | trap _exit-application-mode EXIT | |
54 | } | |
55 | # match zkbd hash as best we can to terminfo | |
56 | typeset -gA key | |
57 | key[F1]=$terminfo[kf1] | |
58 | key[F2]=$terminfo[kf2] | |
59 | key[F3]=$terminfo[kf3] | |
60 | key[F4]=$terminfo[kf4] | |
61 | key[F5]=$terminfo[kf5] | |
62 | key[F6]=$terminfo[kf6] | |
63 | key[F7]=$terminfo[kf7] | |
64 | key[F8]=$terminfo[kf8] | |
65 | key[F9]=$terminfo[kf9] | |
66 | key[F10]=$terminfo[kf10] | |
67 | key[F11]=$terminfo[kf11] | |
68 | key[F12]=$terminfo[kf12] | |
69 | key[Backspace]=$terminfo[kbs] | |
70 | key[Insert]=$terminfo[kich1] | |
71 | key[Home]=$terminfo[khome] | |
72 | key[PageUp]=$terminfo[kpp] | |
73 | key[Delete]=$terminfo[kdch1] | |
74 | key[End]=$terminfo[kend] | |
75 | key[PageDown]=$terminfo[knp] | |
76 | key[Up]=$terminfo[kcuu1] | |
77 | key[Down]=$terminfo[kcud1] | |
78 | key[Left]=$terminfo[kcub1] | |
79 | key[Right]=$terminfo[kcuf1] | |
80 | #key[Menu]=$terminfo[] #TODO: not in termcap? | |
81 | } | |
82 | ||
83 | ## bind keys in both viins and vicmd modes | |
84 | function multibind { | |
85 | local k=$key[$1] | |
86 | if [[ -n $k ]] { | |
87 | bindkey -- $k $2 | |
88 | if [[ -v 3 ]] { | |
89 | # - will use same command as viins | |
90 | bindkey -a -- $k ${3:/-/$2} | |
91 | } | |
92 | } | |
93 | } | |
94 | multibind Backspace backward-delete-char vi-backward-char | |
95 | multibind Insert overwrite-mode vi-insert | |
96 | multibind Home beginning-of-line - | |
97 | multibind PageUp up-line-or-history - | |
98 | multibind Delete delete-char vi-delete-char | |
99 | multibind End end-of-line - | |
100 | multibind PageDown down-line-or-history - | |
101 | multibind Left backward-char vi-backward-char | |
102 | multibind Right forward-char vi-forward-char | |
103 | ## history search | |
104 | autoload -Uz up-line-or-beginning-search down-line-or-beginning-search | |
105 | zle -N up-line-or-beginning-search | |
106 | multibind Up up-line-or-beginning-search - | |
107 | zle -N down-line-or-beginning-search | |
108 | multibind Down down-line-or-beginning-search - | |
109 | unfunction multibind | |
110 | ||
111 | ### aliases | |
112 | ## generic abbreviations | |
113 | alias h="history -25" | |
114 | alias j="jobs -l" | |
115 | alias l="ls -AF" | |
116 | alias p="${PAGER:-more}" # TODO: make sure more is there or use safe default | |
117 | alias e="${EDITOR:-vi}" # TODO: make sure vi is there or use safe default | |
118 | if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] { | |
119 | alias ll="ls -lAFho" | |
120 | } else { | |
121 | alias ll="ls -lAFh" | |
122 | } | |
123 | alias se=sudoedit | |
124 | ## be paranoid | |
125 | alias cp='cp -ip' | |
126 | alias mv='mv -i' | |
127 | if [[ "$OSTYPE" =~ '^freebsd' ]] { | |
128 | # don't confirm if only a few files are deleted | |
129 | alias rm='rm -I' | |
130 | } else { | |
131 | # TODO: similar behavior for non-freebsd, or impliment in zsh | |
132 | alias rm='rm -i' | |
133 | } | |
134 | ## go up directories | |
135 | function up { | |
136 | cd $(printf '../%.0s' {1..${1:-1}}) | |
137 | } | |
138 | ## py venv | |
139 | alias va="source bin/activate" | |
140 | alias vd="deactivate" | |
141 | ## ps | |
142 | # source helper function | |
143 | source ~/bin/.check-busybox | |
144 | if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then | |
145 | # use pstree, but NOT busybox pstree because it kinda sucks | |
146 | ps="pstree -wg3" | |
147 | elif [[ "$OSTYPE" =~ '^freebsd' ]]; then | |
148 | ps="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \ | |
149 | -o%cpu,%mem,tty,stat,start=START -oetime,command" | |
150 | elif check-busybox ps; then | |
151 | # busybox compatible | |
152 | ps="ps -eouser='USR ' -ogroup='GRP ' \ | |
153 | -opid=' PID' -onice=' NI' -ovsz=' MEM' \ | |
154 | -otty,stat,etime,comm" | |
155 | else | |
156 | # XXX: untested, posix | |
157 | # TODO: support gnu ps | |
158 | ps="ps -eouser=USR -ogroup=GRP -opid,nice=NI \ | |
159 | -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm" | |
160 | fi | |
161 | unfunction check-busybox | |
162 | if [[ "$(basename "$PAGER")" = "less" ]] { | |
163 | ps="$ps | less -SE" | |
164 | } else { | |
165 | ps="$ps | \"${PAGER:-more}\"" | |
166 | } | |
167 | alias pa="$ps" | |
168 | alias spa="sudo $ps" | |
169 | unset ps | |
170 | ||
171 | ### hooks | |
172 | autoload -Uz add-zsh-hook | |
173 | _sev_exectime= | |
174 | function sev_preexec { | |
175 | # change terminal title to show command | |
176 | print -n "\e]2;$(print -P '%#')${SSH_CLIENT+$USER@$HOST:}$1\e\\" | |
177 | # save last exec time for bell | |
178 | # XXX: does not run for blank cmdline | |
179 | _sev_exectime=$SECONDS | |
180 | } | |
181 | add-zsh-hook preexec sev_preexec | |
182 | function sev_precmd { | |
183 | # change terminal title | |
184 | # TODO: update and send BEL when job status changes | |
185 | print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\" | |
186 | # bell if exec takes 5s | |
187 | if (( SECONDS - _sev_exectime >= 5 )) print "\a" | |
188 | # we could update vcs_info here, but let prompt take care of it | |
189 | # if it doesn't use vcs, it can be ignored safely | |
190 | } | |
191 | add-zsh-hook precmd sev_precmd | |
192 | function sev_chpwd { | |
193 | # echo dir on cwd change | |
194 | ls -AF | |
195 | } | |
196 | add-zsh-hook chpwd sev_chpwd | |
197 | ||
198 | ### system-specific configs and aliases | |
199 | case "$OSTYPE"; in | |
200 | freebsd*) | |
201 | # colors | |
202 | export CLICOLOR= | |
203 | export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30' | |
204 | ||
205 | ## sound | |
206 | function s { sysctl hw.snd.default_unit${1:+\=$1} } | |
207 | alias vol mixer | |
208 | ||
209 | ## install port dependencies from pkg (like pkgsrc `bmake bin-install') | |
210 | # XXX: should probably use package-depends where possible, breaks when | |
211 | # port name is different to package name | |
212 | # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc) | |
213 | function portpkg { | |
214 | case "$1" { | |
215 | build|run) | |
216 | sudo pkg install -AU $(make ${1}-depends-list | | |
217 | sed 's_/usr/ports/_ _' | tr -d '\n') | |
218 | ;; | |
219 | *) echo "Usage: \`portpkg <build|run>' in a port directory" | |
220 | return 1;; | |
221 | } | |
222 | };; | |
223 | netbsd) | |
224 | ## sound | |
225 | function s { | |
226 | if [[ -z "$1" ]] { | |
227 | ll /dev/mixer /dev/sound /dev/audio | |
228 | return | |
229 | } | |
230 | for x in mixer sound audio; do | |
231 | ln -sf /dev/$x"$1" /dev/$x | |
232 | done | |
233 | } | |
234 | function vol { | |
235 | if [[ -z "$1" ]] { | |
236 | for x in $(mixerctl -a | grep 'outputs\.master'); do | |
237 | echo $x | |
238 | done | |
239 | return | |
240 | } | |
241 | mixerctl -w outputs.master"$2"="$1" | |
242 | };; | |
243 | *) | |
244 | ## sound | |
245 | # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance | |
246 | function s {} | |
247 | function vol {} | |
248 | esac | |
249 | ||
250 | ### modules & styles | |
251 | ## vcs | |
252 | zstyle ':vcs_info:*' enable git | |
253 | #zstyle ':vcs_info:git*' check-for-changes true #too slow | |
254 | zstyle ':vcs_info:git*:dotfiles' check-for-changes true | |
255 | zstyle ':vcs_info:git*' check-for-staged-changes true | |
256 | autoload -Uz vcs_info | |
257 | ||
258 | ## compinit | |
259 | zstyle ':completion:*' auto-description '[arg] %d' | |
260 | zstyle ':completion:*' expand suffix | |
261 | zstyle ':completion:*' format '# %d' | |
262 | zstyle ':completion:*' group-name '' | |
263 | zstyle ':completion:*' ignore-parents parent | |
264 | zstyle ':completion:*' insert-unambiguous false | |
265 | zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} | |
266 | zstyle ':completion:*' list-prompt '%B%i%b' | |
267 | zstyle ':completion:*' list-suffixes true | |
268 | zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' | |
269 | zstyle ':completion:*' menu select=1 | |
270 | zstyle ':completion:*' original false | |
271 | zstyle ':completion:*' select-prompt '%B%l%b' | |
272 | zstyle ':completion:*' verbose true | |
273 | autoload -Uz compinit && compinit | |
274 | ||
275 | ### prompt | |
276 | autoload -Uz promptinit && promptinit | |
277 | prompt arrows | |
278 | ||
81c3957e | 279 | ### load site-specific |
280 | if [[ -f ~/.zshrc.local ]] { source ~/.zshrc.local } | |
b3de8395 | 281 | |
1f53b630 | 282 | # vim: set et sts=4 sw=4 ts=8 tw=79 : |