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 [[ -v commands[zoxide] ]] && eval "$(zoxide init zsh)"
201 autoload -Uz add-zsh-hook
203 function sev_preexec {
204 # change terminal title to show command
205 print -n "\e]2;$(print -P '%#')${SSH_CLIENT+$USER@$HOST:}$1\e\\"
206 # save last exec time for bell
207 # XXX: does not run for blank cmdline
208 _sev_exectime=$SECONDS
209 # update gpg forward, to always have unique filename and avoid clashes
210 if [[ -v _GNUPG_SOCK_DEST_EXT ]] {
211 export _GNUPG_SOCK_DEST_EXT=$(date +%s).$RANDOM
212 export _GNUPG_SOCK_DEST=$_GNUPG_SOCK_DEST_BASE.$_GNUPG_SOCK_DEST_EXT
215 add-zsh-hook preexec sev_preexec
216 function sev_precmd {
217 # change terminal title
218 # TODO: update and send BEL when job status changes
219 print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\"
220 # bell if exec takes 5s
221 if (( SECONDS - _sev_exectime >= 5 )) print "\a"
222 # we could update vcs_info here, but let prompt take care of it
223 # if it doesn't use vcs, it can be ignored safely
225 add-zsh-hook precmd sev_precmd
227 # echo dir on cwd change
230 add-zsh-hook chpwd sev_chpwd
232 ### system-specific configs and aliases
237 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'
240 function s { sysctl hw.snd.default_unit${1:+\=$1} }
243 ## install port dependencies from pkg (like pkgsrc `bmake bin-install')
244 # XXX: should probably use package-depends where possible, breaks when
245 # port name is different to package name
246 # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc)
250 sudo pkg install -AU $(make ${1}-depends-list |
251 sed 's_/usr/ports/_ _' | tr -d '\n')
253 *) echo "Usage: \`portpkg <build|run>' in a port directory"
261 ll /dev/mixer /dev/sound /dev/audio
264 for x in mixer sound audio; do
265 ln -sf /dev/$x"$1" /dev/$x
270 for x in $(mixerctl -a | grep 'outputs\.master'); do
275 mixerctl -w outputs.master"$2"="$1"
279 # TODO: test alsa/oss/sndio/portaudio/pulse/pipewire in order of importance
286 zstyle ':vcs_info:*' enable git
287 #zstyle ':vcs_info:git*' check-for-changes true #too slow
288 zstyle ':vcs_info:git*:dotfiles' check-for-changes true
289 zstyle ':vcs_info:git*' check-for-staged-changes true
290 autoload -Uz vcs_info
293 zstyle ':completion:*' auto-description '[arg] %d'
294 zstyle ':completion:*' expand suffix
295 zstyle ':completion:*' format '# %d'
296 zstyle ':completion:*' group-name ''
297 zstyle ':completion:*' ignore-parents parent
298 zstyle ':completion:*' insert-unambiguous false
299 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
300 zstyle ':completion:*' list-prompt '%B%i%b'
301 zstyle ':completion:*' list-suffixes true
302 zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
303 zstyle ':completion:*' menu select=1
304 zstyle ':completion:*' original false
305 zstyle ':completion:*' select-prompt '%B%l%b'
306 zstyle ':completion:*' verbose true
307 autoload -Uz compinit
308 cache=${XDG_CACHE_HOME:-~/.cache}/zsh
309 [[ -d $cache ]] || mkdir -p $cache
310 compinit -d $cache/.zcompdump
314 autoload -Uz promptinit && promptinit
317 ### load site-specific
318 load-site-dotfile zshrc