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 export EDITOR=${$(whence -p nvim vim vi micro nano emacs)[(f)1]}
13 export PAGER=${$(whence -p less micro nano more)[(f)1]:s/micro/& -readonly true -multiopen tab/:s/nano/& --view}
15 # XXX: deprecated in GNU
16 export GREP_OPTIONS=--color=auto
18 export HISTFILE=~/.histfile
22 export PYTHONSTARTUP=${XDG_CONFIG_HOME:-~/.config}/pythonrc
24 export VIMINIT='let$MYVIMRC=($XDG_CONFIG_HOME??($HOME."/.config"))."/vim/.vimrc"|execute"source"$MYVIMRC'
26 export XDG_SESSION_TYPE=${XDG_SESSION_TYPE:-wayland}
27 export QT_QPA_PLATFORM=${QT_QPA_PLATFORM:-wayland-egl}
28 export QT_WAYLAND_DISABLE_WINDOWDECORATION=${QT_WAYLAND_DISABLE_WINDOWDECORATION:--1}
29 export SDL_VIDEODRIVER=${SDL_VIDEODRIVER:-wayland}
30 export TERMINAL=${TERMINAL:-$(whence -p konsole footclient urxvt xterm)[(f)1]}
34 autoload -Uz zmathfunc && zmathfunc
37 zstyle ':vcs_info:*' enable git
38 #zstyle ':vcs_info:git*' check-for-changes true #too slow
39 zstyle ':vcs_info:git*:dotfiles' check-for-changes true
40 zstyle ':vcs_info:git*' check-for-staged-changes true
44 zstyle ':completion:*' auto-description '[arg] %d'
45 zstyle ':completion:*' expand suffix
46 zstyle ':completion:*' format '# %d'
47 zstyle ':completion:*' group-name ''
48 zstyle ':completion:*' ignore-parents parent
49 zstyle ':completion:*' insert-unambiguous false
50 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
51 zstyle ':completion:*' list-prompt '%B%i%b'
52 zstyle ':completion:*' list-suffixes true
53 zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
54 zstyle ':completion:*' menu select=1
55 zstyle ':completion:*' original false
56 zstyle ':completion:*' select-prompt '%B%l%b'
57 zstyle ':completion:*' verbose true
59 cache=${XDG_CACHE_HOME:-~/.cache}/zsh
60 [[ -d $cache ]] || mkdir -p $cache
61 compinit -d $cache/.zcompdump
68 if (( $#terminfo == 0 )) {
69 # terminfo is not set or empty
70 function find_keymap {
71 for f in ${ZDOTDIR:-~}/.zkbd/$TERM{-${DISPLAY:-$VENDOR-$OSTYPE},}
72 [[ -f $f ]] && keymap=$f && break
76 if read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]"; then
78 autoload -Uz zkbd && zkbd
87 echo "Failed to source keymap file $keymap" >&2
89 unfunction find_keymap; unset keymap
91 # activate application mode for zle so terminfo keys work
92 # NOTE: don't do this for zkbd since application mode shouldn't have been
93 # enabled by zkbd when the keymap file was generated
94 if [[ -v terminfo[smkx] && -v terminfo[rmkx] ]] {
95 autoload -Uz add-zle-hook-widget
96 function _enter-application-mode { echoti smkx }
97 add-zle-hook-widget line-init _enter-application-mode
98 function _exit-application-mode { echoti rmkx }
99 add-zle-hook-widget line-finish _exit-application-mode
100 trap _exit-application-mode EXIT
102 # match zkbd hash as best we can to terminfo
104 key=(F1 kf1 F2 kf2 F3 kf3 F4 kf4 F5 kf5 F6 kf6 F7 kf7 F8 kf8 F9 kf9
105 F10 kf10 F11 kf11 F12 kf12
120 for k v in ${(kv)key}; do
121 key[$k]=$terminfo[$v]
125 ## load history search
126 autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
127 zle -N up-line-or-beginning-search
128 zle -N down-line-or-beginning-search
130 ## bind keys in both viins and vicmd modes
134 Backspace 'backward-delete-char vi-backward-char'
135 Insert 'overwrite-mode vi-insert'
136 Home 'beginning-of-line'
137 PageUp 'up-history -'
140 PageDown 'down-history -'
141 Up 'up-line-or-beginning-search vi-up-line-or-history'
142 Down 'down-line-or-beginning-search vi-down-line-or-history'
146 for k v in ${(kv)a}; do
148 if [[ -z "$k" ]] { continue }
151 if [[ $v[2] == '-' ]] {
152 # copy viins to vicmd verbatim
153 bindkey -a -- $k $v[1]
154 } elif (( $#v != 1 )) {
155 # set vicmd to any other value
156 bindkey -a -- $k $v[2]
158 # copy viins to vicmd and prepend vi- to it
159 bindkey -a -- $k vi-$v[1]
164 ### abbreviation aliases
168 if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] {
179 if [[ "$OSTYPE" =~ '^freebsd' ]] {
180 # don't confirm if only a few files are deleted
183 # TODO: similar behavior for non-freebsd, or impliment in zsh
186 [[ -v commands[trash-put] ]] && alias t=trash-put
188 alias va='source bin/activate'
191 source ~/.local/bin/.check-busybox
192 if [[ -v commands[pstree] ]] && ! check-busybox pstree; then
193 # use pstree, but NOT busybox pstree because it kinda sucks
195 elif [[ "$OSTYPE" =~ '^freebsd' ]]; then
196 ps="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
197 -o%cpu,%mem,tty,stat,start=START -oetime,command"
198 elif check-busybox ps; then
200 ps="ps -eouser='USR ' -ogroup='GRP ' \
201 -opid=' PID' -onice=' NI' -ovsz=' MEM' \
202 -otty,stat,etime,comm"
204 # XXX: untested, posix
205 # TODO: support gnu ps
206 ps="ps -eouser=USR -ogroup=GRP -opid,nice=NI \
207 -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm"
209 unfunction check-busybox
210 if [[ "$(basename "$PAGER")" = "less" ]] {
213 ps="$ps | \"${PAGER:-more}\""
219 alias gdh='git diff HEAD'
221 alias gc='git commit'
222 alias gca='git commit --amend'
226 \cd $(printf '../%.0s' {1..${1:-1}})
229 if [[ -v commands[zoxide] ]] {
230 eval "$(zoxide init zsh)"
235 autoload -Uz add-zsh-hook
237 function sev_preexec {
238 # change terminal title to show command
239 print -n "\e]2;$(print -P '%#')${SSH_CLIENT+$USER@$HOST:}$1\e\\"
240 # save last exec time for bell
241 # XXX: does not run for blank cmdline
242 _sev_exectime=$SECONDS
243 # update gpg forward, to always have unique filename and avoid clashes
244 if [[ -v _GNUPG_SOCK_DEST_EXT ]] {
245 export _GNUPG_SOCK_DEST_EXT=$(date +%s).$RANDOM
246 export _GNUPG_SOCK_DEST=$_GNUPG_SOCK_DEST_BASE.$_GNUPG_SOCK_DEST_EXT
249 add-zsh-hook preexec sev_preexec
250 function sev_precmd {
251 # change terminal title
252 # TODO: update and send BEL when job status changes
253 print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\"
254 # bell if exec takes 5s
255 if (( SECONDS - _sev_exectime >= 5 )) print "\a"
256 # we could update vcs_info here, but let prompt take care of it
257 # if it doesn't use vcs, it can be ignored safely
259 add-zsh-hook precmd sev_precmd
261 # echo dir on cwd change
264 add-zsh-hook chpwd sev_chpwd
266 ### system-specific configs and aliases
271 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'
274 function s { sysctl hw.snd.default_unit${1:+\=$1} }
277 ## install port dependencies from pkg (like pkgsrc `bmake bin-install')
278 # XXX: should probably use package-depends where possible, breaks when
279 # port name is different to package name
280 # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc)
284 sudo pkg install -AU $(make ${1}-depends-list |
285 sed 's_/usr/ports/_ _' | tr -d '\n')
287 *) echo "Usage: \`portpkg <build|run>' in a port directory"
295 ll /dev/mixer /dev/sound /dev/audio
298 for x in mixer sound audio; do
299 ln -sf /dev/$x"$1" /dev/$x
304 for x in $(mixerctl -a | grep 'outputs\.master'); do
309 mixerctl -w outputs.master"$2"="$1"
313 # TODO: test alsa/oss/sndio/portaudio/pulse/pipewire in order of importance
319 autoload -Uz promptinit && promptinit
322 ### load site-specific
323 load-site-dotfile zshrc