2 setopt NO_BEEP NO_CLOBBER
4 setopt AUTO_CD CDABLE_VARS
8 setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT
10 setopt AUTO_CONTINUE LONG_LIST_JOBS
12 setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY HIST_REDUCE_BLANKS
16 autoload -Uz zmathfunc && zmathfunc
23 # XXX: deprecated in GNU
24 export GREP_OPTIONS=--color=auto
26 export HISTFILE=~/.histfile
30 export PYTHONSTARTUP=~/.pythonrc
32 # XXX: only do this if we're actually in wayland, but without a start script
33 export XDG_SESSION_TYPE=wayland
34 export QT_QPA_PLATFORM=wayland-egl
35 export QT_WAYLAND_DISABLE_WINDOWDECORATION=-1
36 export SDL_VIDEODRIVER=wayland
37 export TERMINAL=footclient
43 if (( $#terminfo == 0 )) {
44 # terminfo is not set or empty
45 function find_keymap {
46 for f in ${ZDOTDIR:-$HOME}/.zkbd/$TERM{-${DISPLAY:-$VENDOR-$OSTYPE},}
47 [[ -f $f ]] && keymap=$f && break
51 if read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]"; then
53 autoload -Uz zkbd && zkbd
62 echo "Failed to source keymap file $keymap" >&2
64 unfunction find_keymap; unset keymap
66 # activate application mode for zle so terminfo keys work
67 # NOTE: don't do this for zkbd since application mode shouldn't have been
68 # enabled by zkbd when the keymap file was generated
69 if [[ -v terminfo[smkx] && -v terminfo[rmkx] ]] {
70 autoload -Uz add-zle-hook-widget
71 function _enter-application-mode { echoti smkx }
72 add-zle-hook-widget line-init _enter-application-mode
73 function _exit-application-mode { echoti rmkx }
74 add-zle-hook-widget line-finish _exit-application-mode
75 trap _exit-application-mode EXIT
77 # match zkbd hash as best we can to terminfo
79 key=(F1 kf1 F2 kf2 F3 kf3 F4 kf4 F5 kf5 F6 kf6 F7 kf7 F8 kf8 F9 kf9
80 F10 kf10 F11 kf11 F12 kf12
95 for k v in ${(kv)key}; do
99 ## load history search
100 autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
101 zle -N up-line-or-beginning-search
102 zle -N down-line-or-beginning-search
104 ## bind keys in both viins and vicmd modes
108 Backspace 'backward-delete-char vi-backward-char'
109 Insert 'overwrite-mode vi-insert'
110 Home 'beginning-of-line'
111 PageUp 'up-history -'
114 PageDown 'down-history -'
115 Up 'up-line-or-beginning-search vi-up-line-or-history'
116 Down 'down-line-or-beginning-search vi-down-line-or-history'
120 for k v in ${(kv)a}; do
122 if [[ -z "$k" ]] { continue }
125 if [[ $v[2] == '-' ]] {
126 # copy viins to vicmd verbatim
127 bindkey -a -- $k $v[1]
128 } elif (( $#v != 1 )) {
129 # set vicmd to any other value
130 bindkey -a -- $k $v[2]
132 # copy viins to vicmd and prepend vi- to it
133 bindkey -a -- $k vi-$v[1]
138 ### abbreviation aliases
139 alias h='history -25'
142 if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] {
147 alias p=${PAGER:-more} # TODO: make sure more is there or use alternate
148 alias e=${EDITOR:-vi} # TODO: make sure vi is there or use alternate
153 if [[ "$OSTYPE" =~ '^freebsd' ]] {
154 # don't confirm if only a few files are deleted
157 # TODO: similar behavior for non-freebsd, or impliment in zsh
161 alias va='source bin/activate'
164 source ~/bin/.check-busybox
165 if [[ -v commands[pstree] ]] && ! check-busybox pstree; then
166 # use pstree, but NOT busybox pstree because it kinda sucks
168 elif [[ "$OSTYPE" =~ '^freebsd' ]]; then
169 ps="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
170 -o%cpu,%mem,tty,stat,start=START -oetime,command"
171 elif check-busybox ps; then
173 ps="ps -eouser='USR ' -ogroup='GRP ' \
174 -opid=' PID' -onice=' NI' -ovsz=' MEM' \
175 -otty,stat,etime,comm"
177 # XXX: untested, posix
178 # TODO: support gnu ps
179 ps="ps -eouser=USR -ogroup=GRP -opid,nice=NI \
180 -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm"
182 unfunction check-busybox
183 if [[ "$(basename "$PAGER")" = "less" ]] {
186 ps="$ps | \"${PAGER:-more}\""
192 ### specialized aliases
195 cd $(printf '../%.0s' {1..${1:-1}})
199 [[ -v commands[zoxide] ]] && eval "$(zoxide init zsh)"
202 autoload -Uz add-zsh-hook
204 function sev_preexec {
205 # change terminal title to show command
206 print -n "\e]2;$(print -P '%#')${SSH_CLIENT+$USER@$HOST:}$1\e\\"
207 # save last exec time for bell
208 # XXX: does not run for blank cmdline
209 _sev_exectime=$SECONDS
210 # update gpg forward, to always have unique filename and avoid clashes
211 if [[ -v _GNUPG_SOCK_DEST_EXT ]] {
212 export _GNUPG_SOCK_DEST_EXT=$(date +%s).$RANDOM
213 export _GNUPG_SOCK_DEST=$_GNUPG_SOCK_DEST_BASE.$_GNUPG_SOCK_DEST_EXT
216 add-zsh-hook preexec sev_preexec
217 function sev_precmd {
218 # change terminal title
219 # TODO: update and send BEL when job status changes
220 print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\"
221 # bell if exec takes 5s
222 if (( SECONDS - _sev_exectime >= 5 )) print "\a"
223 # we could update vcs_info here, but let prompt take care of it
224 # if it doesn't use vcs, it can be ignored safely
226 add-zsh-hook precmd sev_precmd
228 # echo dir on cwd change
231 add-zsh-hook chpwd sev_chpwd
233 ### system-specific configs and aliases
238 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'
241 function s { sysctl hw.snd.default_unit${1:+\=$1} }
244 ## install port dependencies from pkg (like pkgsrc `bmake bin-install')
245 # XXX: should probably use package-depends where possible, breaks when
246 # port name is different to package name
247 # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc)
251 sudo pkg install -AU $(make ${1}-depends-list |
252 sed 's_/usr/ports/_ _' | tr -d '\n')
254 *) echo "Usage: \`portpkg <build|run>' in a port directory"
262 ll /dev/mixer /dev/sound /dev/audio
265 for x in mixer sound audio; do
266 ln -sf /dev/$x"$1" /dev/$x
271 for x in $(mixerctl -a | grep 'outputs\.master'); do
276 mixerctl -w outputs.master"$2"="$1"
280 # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance
287 zstyle ':vcs_info:*' enable git
288 #zstyle ':vcs_info:git*' check-for-changes true #too slow
289 zstyle ':vcs_info:git*:dotfiles' check-for-changes true
290 zstyle ':vcs_info:git*' check-for-staged-changes true
291 autoload -Uz vcs_info
294 zstyle ':completion:*' auto-description '[arg] %d'
295 zstyle ':completion:*' expand suffix
296 zstyle ':completion:*' format '# %d'
297 zstyle ':completion:*' group-name ''
298 zstyle ':completion:*' ignore-parents parent
299 zstyle ':completion:*' insert-unambiguous false
300 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
301 zstyle ':completion:*' list-prompt '%B%i%b'
302 zstyle ':completion:*' list-suffixes true
303 zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
304 zstyle ':completion:*' menu select=1
305 zstyle ':completion:*' original false
306 zstyle ':completion:*' select-prompt '%B%l%b'
307 zstyle ':completion:*' verbose true
308 autoload -Uz compinit && compinit
311 autoload -Uz promptinit && promptinit
314 ### load site-specific
315 if [[ -f ~/.zshrc.local ]] { source ~/.zshrc.local }
317 # vim: et sts=4 sw=4 ts=8 tw=79