2 setopt NO_BEEP NO_CLOBBER \
4 EXTENDED_GLOB GLOB_DOTS GLOB_STAR_SHORT MARK_DIRS NUMERIC_GLOB_SORT \
5 CORRECT_ALL INTERACTIVE_COMMENTS \
7 AUTO_CONTINUE LONG_LIST_JOBS \
8 NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY HIST_REDUCE_BLANKS
12 autoload -Uz zmathfunc && zmathfunc
16 export EDITOR=${$(whence -p nvim vim vi micro nano emacs)[(f)1]}
17 export PAGER=${$(whence -p less micro nano more)[(f)1]:s/micro/& -readonly true -multiopen tab/:s/nano/& --view}
19 # XXX: deprecated in GNU
20 export GREP_OPTIONS=--color=auto
22 export HISTFILE=~/.histfile
26 export PYTHONSTARTUP=${XDG_CONFIG_HOME:-~/.config}/pythonrc
28 export VIMINIT='let$MYVIMRC=($XDG_CONFIG_HOME??($HOME."/.config"))."/vim/.vimrc"|execute"source"$MYVIMRC'
30 # XXX: only do this if we're actually in wayland, but without a start script
31 export XDG_SESSION_TYPE=wayland
32 export QT_QPA_PLATFORM=wayland-egl
33 export QT_WAYLAND_DISABLE_WINDOWDECORATION=-1
34 export SDL_VIDEODRIVER=wayland
35 export TERMINAL=${$(whence -p konsole footclient urxvt xterm)[(f)1]}
41 if (( $#terminfo == 0 )) {
42 # terminfo is not set or empty
43 function find_keymap {
44 for f in ${ZDOTDIR:-~}/.zkbd/$TERM{-${DISPLAY:-$VENDOR-$OSTYPE},}
45 [[ -f $f ]] && keymap=$f && break
49 if read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]"; then
51 autoload -Uz zkbd && zkbd
60 echo "Failed to source keymap file $keymap" >&2
62 unfunction find_keymap; unset keymap
64 # activate application mode for zle so terminfo keys work
65 # NOTE: don't do this for zkbd since application mode shouldn't have been
66 # enabled by zkbd when the keymap file was generated
67 if [[ -v terminfo[smkx] && -v terminfo[rmkx] ]] {
68 autoload -Uz add-zle-hook-widget
69 function _enter-application-mode { echoti smkx }
70 add-zle-hook-widget line-init _enter-application-mode
71 function _exit-application-mode { echoti rmkx }
72 add-zle-hook-widget line-finish _exit-application-mode
73 trap _exit-application-mode EXIT
75 # match zkbd hash as best we can to terminfo
77 key=(F1 kf1 F2 kf2 F3 kf3 F4 kf4 F5 kf5 F6 kf6 F7 kf7 F8 kf8 F9 kf9
78 F10 kf10 F11 kf11 F12 kf12
93 for k v in ${(kv)key}; do
97 ## load history search
98 autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
99 zle -N up-line-or-beginning-search
100 zle -N down-line-or-beginning-search
102 ## bind keys in both viins and vicmd modes
106 Backspace 'backward-delete-char vi-backward-char'
107 Insert 'overwrite-mode vi-insert'
108 Home 'beginning-of-line'
109 PageUp 'up-history -'
112 PageDown 'down-history -'
113 Up 'up-line-or-beginning-search vi-up-line-or-history'
114 Down 'down-line-or-beginning-search vi-down-line-or-history'
118 for k v in ${(kv)a}; do
120 if [[ -z "$k" ]] { continue }
123 if [[ $v[2] == '-' ]] {
124 # copy viins to vicmd verbatim
125 bindkey -a -- $k $v[1]
126 } elif (( $#v != 1 )) {
127 # set vicmd to any other value
128 bindkey -a -- $k $v[2]
130 # copy viins to vicmd and prepend vi- to it
131 bindkey -a -- $k vi-$v[1]
136 ### abbreviation aliases
140 if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] {
151 if [[ "$OSTYPE" =~ '^freebsd' ]] {
152 # don't confirm if only a few files are deleted
155 # TODO: similar behavior for non-freebsd, or impliment in zsh
158 [[ -v commands[trash-put] ]] && alias t=trash-put
160 alias va='source bin/activate'
163 source ~/.local/bin/.check-busybox
164 if [[ -v commands[pstree] ]] && ! check-busybox pstree; then
165 # use pstree, but NOT busybox pstree because it kinda sucks
167 elif [[ "$OSTYPE" =~ '^freebsd' ]]; then
168 ps="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
169 -o%cpu,%mem,tty,stat,start=START -oetime,command"
170 elif check-busybox ps; then
172 ps="ps -eouser='USR ' -ogroup='GRP ' \
173 -opid=' PID' -onice=' NI' -ovsz=' MEM' \
174 -otty,stat,etime,comm"
176 # XXX: untested, posix
177 # TODO: support gnu ps
178 ps="ps -eouser=USR -ogroup=GRP -opid,nice=NI \
179 -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm"
181 unfunction check-busybox
182 if [[ "$(basename "$PAGER")" = "less" ]] {
185 ps="$ps | \"${PAGER:-more}\""
191 ### specialized aliases
194 \cd $(printf '../%.0s' {1..${1:-1}})
198 if [[ -v commands[zoxide] ]] {
199 eval "$(zoxide init zsh)"
204 alias gdh='git diff HEAD'
207 autoload -Uz add-zsh-hook
209 function sev_preexec {
210 # change terminal title to show command
211 print -n "\e]2;$(print -P '%#')${SSH_CLIENT+$USER@$HOST:}$1\e\\"
212 # save last exec time for bell
213 # XXX: does not run for blank cmdline
214 _sev_exectime=$SECONDS
215 # update gpg forward, to always have unique filename and avoid clashes
216 if [[ -v _GNUPG_SOCK_DEST_EXT ]] {
217 export _GNUPG_SOCK_DEST_EXT=$(date +%s).$RANDOM
218 export _GNUPG_SOCK_DEST=$_GNUPG_SOCK_DEST_BASE.$_GNUPG_SOCK_DEST_EXT
221 add-zsh-hook preexec sev_preexec
222 function sev_precmd {
223 # change terminal title
224 # TODO: update and send BEL when job status changes
225 print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\"
226 # bell if exec takes 5s
227 if (( SECONDS - _sev_exectime >= 5 )) print "\a"
228 # we could update vcs_info here, but let prompt take care of it
229 # if it doesn't use vcs, it can be ignored safely
231 add-zsh-hook precmd sev_precmd
233 # echo dir on cwd change
236 add-zsh-hook chpwd sev_chpwd
238 ### system-specific configs and aliases
243 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'
246 function s { sysctl hw.snd.default_unit${1:+\=$1} }
249 ## install port dependencies from pkg (like pkgsrc `bmake bin-install')
250 # XXX: should probably use package-depends where possible, breaks when
251 # port name is different to package name
252 # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc)
256 sudo pkg install -AU $(make ${1}-depends-list |
257 sed 's_/usr/ports/_ _' | tr -d '\n')
259 *) echo "Usage: \`portpkg <build|run>' in a port directory"
267 ll /dev/mixer /dev/sound /dev/audio
270 for x in mixer sound audio; do
271 ln -sf /dev/$x"$1" /dev/$x
276 for x in $(mixerctl -a | grep 'outputs\.master'); do
281 mixerctl -w outputs.master"$2"="$1"
285 # TODO: test alsa/oss/sndio/portaudio/pulse/pipewire in order of importance
292 zstyle ':vcs_info:*' enable git
293 #zstyle ':vcs_info:git*' check-for-changes true #too slow
294 zstyle ':vcs_info:git*:dotfiles' check-for-changes true
295 zstyle ':vcs_info:git*' check-for-staged-changes true
296 autoload -Uz vcs_info
299 zstyle ':completion:*' auto-description '[arg] %d'
300 zstyle ':completion:*' expand suffix
301 zstyle ':completion:*' format '# %d'
302 zstyle ':completion:*' group-name ''
303 zstyle ':completion:*' ignore-parents parent
304 zstyle ':completion:*' insert-unambiguous false
305 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
306 zstyle ':completion:*' list-prompt '%B%i%b'
307 zstyle ':completion:*' list-suffixes true
308 zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
309 zstyle ':completion:*' menu select=1
310 zstyle ':completion:*' original false
311 zstyle ':completion:*' select-prompt '%B%l%b'
312 zstyle ':completion:*' verbose true
313 autoload -Uz compinit
314 cache=${XDG_CACHE_HOME:-~/.cache}/zsh
315 [[ -d $cache ]] || mkdir -p $cache
316 compinit -d $cache/.zcompdump
320 autoload -Uz promptinit && promptinit
323 ### load site-specific
324 load-site-dotfile zshrc