2 setopt NO_BEEP NO_CLOBBER
4 setopt AUTO_CD CDABLE_VARS
8 setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT
14 setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY
17 # TODO: investigate "^[[200~" bracketed-paste
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
29 if read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]"; then
31 autoload -Uz zkbd && zkbd
40 echo "Failed to source keymap file $keymap" >&2
42 unfunction find_keymap; unset keymap
44 # activate application mode for zle so terminfo keys work
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
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
55 # match zkbd hash as best we can to terminfo
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?
83 ## bind keys in both viins and vicmd modes
89 # - will use same command as viins
90 bindkey -a -- $k ${3:/-/$2}
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
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 -
112 ## generic abbreviations
113 alias h="history -25"
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' ]] {
127 if [[ "$OSTYPE" =~ '^freebsd' ]] {
128 # don't confirm if only a few files are deleted
131 # TODO: similar behavior for non-freebsd, or impliment in zsh
136 cd $(printf '../%.0s' {1..${1:-1}})
139 alias va="source bin/activate"
140 alias vd="deactivate"
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
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
152 ps="ps -eouser='USR ' -ogroup='GRP ' \
153 -opid=' PID' -onice=' NI' -ovsz=' MEM' \
154 -otty,stat,etime,comm"
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"
161 unfunction check-busybox
162 if [[ "$(basename "$PAGER")" = "less" ]] {
165 ps="$ps | \"${PAGER:-more}\""
172 autoload -Uz add-zsh-hook
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
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
191 add-zsh-hook precmd sev_precmd
193 # echo dir on cwd change
196 add-zsh-hook chpwd sev_chpwd
198 ### system-specific configs and aliases
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'
206 function s { sysctl hw.snd.default_unit${1:+\=$1} }
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)
216 sudo pkg install -AU $(make ${1}-depends-list |
217 sed 's_/usr/ports/_ _' | tr -d '\n')
219 *) echo "Usage: \`portpkg <build|run>' in a port directory"
227 ll /dev/mixer /dev/sound /dev/audio
230 for x in mixer sound audio; do
231 ln -sf /dev/$x"$1" /dev/$x
236 for x in $(mixerctl -a | grep 'outputs\.master'); do
241 mixerctl -w outputs.master"$2"="$1"
245 # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance
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
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
276 autoload -Uz promptinit && promptinit
279 ### load site-specific
280 if [[ -f ~/.zshrc.local ]] { source ~/.zshrc.local }
282 # vim: set et sts=4 sw=4 ts=8 tw=79 :