2 source ~/bin/.check-busybox
5 ## reset PATH to prevent /etc/zprofile from changing it
6 # some distros put non-interactive PATH in env and interactive PATH in profile;
7 # we want to make sure to always use ours regardless
8 if [[ -v _sev_backup_path ]] {
9 path=("${_backup_path[@]}" "${path[@]}")
11 unset _sev_backup_path
17 # XXX: deprecated in GNU
18 export GREP_OPTIONS=--color=auto
20 export HISTFILE=~/.histfile
24 export PYTHONSTARTUP=~/.pythonrc
26 [[ -v commands[perl] ]] && eval $(perl -I $XDG_DATA_HOME/perl5/lib/perl5 -Mlocal::lib=$XDG_DATA_HOME/perl5 2>/dev/null)
29 # NOTE: preferred order of agents to check: okcagent, gnupg, openssh
30 # first block takes care of okcagent and openssh, second handles gnupg
31 if [[ ! -v SSH_AUTH_SOCK && ( -v commands[okc-ssh-agent] ||
32 ( -v commands[ssh-agent] && ! -v commands[gpg] ) ) ]] {
33 okc=${commands[okc-ssh-agent]:+okc-}
34 agentfile=~/tmp/${okc}ssh-agent-exports
37 if [[ -f "$agentfile" ]] {
38 IFS=$'\0' read -r sock pid <"$agentfile"
40 if [[ -S "$sock" && $pid -gt 0 ]] && kill -0 $pid; then
41 echo "Reusing ${okc+okc-ssh-}agent pid $pid"
42 export SSH_AUTH_SOCK="$sock"
43 export SSH_AGENT_PID=$pid
45 # TODO: ensure ssh-agent path looks legit
46 # to avoid unsafe eval?
47 eval `${okc}ssh-agent`
48 echo -n "$SSH_AUTH_SOCK"$'\0'$SSH_AGENT_PID >!$agentfile
50 unset okc agentfile sock pid
51 } elif [[ -v commands[gpg] && ! -S $_GNUPG_SOCK_DEST && \
52 ( ! -v SSH_AUTH_SOCK || -v DISPLAY ) ]] {
54 export PINENTRY_USER_DATA=USE_TTY=$((!${+DISPLAY}))
55 gpg-connect-agent UPDATESTARTUPTTY /BYE >/dev/null 2>&1
56 [[ ! -v SSH_AUTH_SOCK ]] && \
57 export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
61 if [[ -v _GNUPG_SOCK_SRC && -v _GNUPG_SOCK_DEST && -S $_GNUPG_SOCK_DEST ]] {
62 unlink $_GNUPG_SOCK_SRC >/dev/null 2>&1
63 mv $_GNUPG_SOCK_DEST $_GNUPG_SOCK_SRC >/dev/null
67 setopt NO_BEEP NO_CLOBBER
69 setopt AUTO_CD CDABLE_VARS
73 setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT
79 setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY
82 # TODO: investigate "^[[200~" bracketed-paste
86 if (( $#terminfo == 0 )) {
87 # terminfo is not set or empty
88 function find_keymap {
89 for f in ${ZDOTDIR:-$HOME}/.zkbd/${TERM}{-${DISPLAY:-${VENDOR}-${OSTYPE}},}
90 [[ -f $f ]] && keymap=$f && break
94 if read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]"; then
96 autoload -Uz zkbd && zkbd
102 if [[ -n $keymap ]] {
105 echo "Failed to source file $keymap" >&2
107 unfunction find_keymap; unset keymap
109 # activate application mode for zle so terminfo keys work
110 # don't do this for zkbd since application mode shouldn't have ben enabled
111 if [[ -v terminfo[smkx] && -v terminfo[rmkx] ]] {
112 autoload -Uz add-zle-hook-widget
113 function _enter-application-mode { echoti smkx }
114 add-zle-hook-widget line-init _enter-application-mode
115 function _exit-application-mode { echoti rmkx }
116 add-zle-hook-widget line-finish _exit-application-mode
117 trap _exit-application-mode EXIT
119 # match zkbd hash as best we can to terminfo
121 key[F1]=$terminfo[kf1]
122 key[F2]=$terminfo[kf2]
123 key[F3]=$terminfo[kf3]
124 key[F4]=$terminfo[kf4]
125 key[F5]=$terminfo[kf5]
126 key[F6]=$terminfo[kf6]
127 key[F7]=$terminfo[kf7]
128 key[F8]=$terminfo[kf8]
129 key[F9]=$terminfo[kf9]
130 key[F10]=$terminfo[kf10]
131 key[F11]=$terminfo[kf11]
132 key[F12]=$terminfo[kf12]
133 key[Backspace]=$terminfo[kbs]
134 key[Insert]=$terminfo[kich1]
135 key[Home]=$terminfo[khome]
136 key[PageUp]=$terminfo[kpp]
137 key[Delete]=$terminfo[kdch1]
138 key[End]=$terminfo[kend]
139 key[PageDown]=$terminfo[knp]
140 key[Up]=$terminfo[kcuu1]
141 key[Down]=$terminfo[kcud1]
142 key[Left]=$terminfo[kcub1]
143 key[Right]=$terminfo[kcuf1]
144 #key[Menu]=$terminfo[] #TODO: not in termcap?
147 ## bind keys in both viins and vicmd modes
153 # - will use same command as viins
154 bindkey -a -- $k ${3:/-/$2}
158 multibind Backspace backward-delete-char vi-backward-char
159 multibind Insert overwrite-mode vi-insert
160 multibind Home beginning-of-line -
161 multibind PageUp up-line-or-history -
162 multibind Delete delete-char vi-delete-char
163 multibind End end-of-line -
164 multibind PageDown down-line-or-history -
165 multibind Left backward-char vi-backward-char
166 multibind Right forward-char vi-forward-char
168 autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
169 zle -N up-line-or-beginning-search
170 multibind Up up-line-or-beginning-search -
171 zle -N down-line-or-beginning-search
172 multibind Down down-line-or-beginning-search -
176 alias h="history -25"
179 alias p="${PAGER:-more}" # TODO: make sure more is there or use safe default
180 alias e="${EDITOR:-vi}" # TODO: make sure vi is there or use safe default
181 if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] {
189 if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then
190 # use pstree, but NOT busybox pstree because it kinda sucks
192 elif [[ "$OSTYPE" =~ '^freebsd' ]]; then
193 p="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
194 -o%cpu,%mem,tty,stat,start=START -oetime,command"
195 elif check-busybox ps; then
197 p="ps -eouser='USR ' -ogroup='GRP ' \
198 -opid=' PID' -onice=' NI' -ovsz=' MEM' \
199 -otty,stat,etime,comm"
201 # XXX: untested, posix
202 # TODO: support gnu ps
203 p="ps -eouser=USR -ogroup=GRP -opid,nice=NI \
204 -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm"
206 if [[ "$(basename "$PAGER")" = "less" ]] {
209 p="$p | \"${PAGER:-more}\""
215 alias va="source bin/activate"
216 alias vd="deactivate"
220 if [[ "$OSTYPE" =~ '^freebsd' ]] {
221 # don't confirm if only a few files are deleted
224 # TODO: similar behavior for non-freebsd, or impliment in zsh
229 cd $(printf '../%.0s' {1..${1:-1}})
233 autoload -Uz add-zsh-hook
235 function sev_precmd {
236 # change terminal title
237 # TODO: update and send BEL when job status changes
238 print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\"
239 # bell if exec takes 5s
240 if (( SECONDS - _sev_exectime >= 5 )) print "\a"
241 # we could update vcs_info here, but let prompt take care of it
242 # if it doesn't use vcs, it can be ignored safely
244 add-zsh-hook precmd sev_precmd
245 function sev_preexec {
246 # change terminal title to show command
247 print -Pnf "\e]2;%s\e\\" "%#${SSH_CLIENT+$USER@$HOST:}$1"
248 # save last exec time for bell
249 # XXX: does not run for blank cmdline
250 _sev_exectime=$SECONDS
252 add-zsh-hook preexec sev_preexec
254 # echo dir on cwd change
257 add-zsh-hook chpwd sev_chpwd
259 ### system-specific configs and aliases
264 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'
267 function s { sysctl hw.snd.default_unit${1:+\=$1} }
270 ## install port dependencies from pkg (like pkgsrc `bmake bin-install')
271 # XXX: should probably use package-depends where possible, breaks when
272 # port name is different to package name
273 # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc)
277 sudo pkg install -AU $(make ${1}-depends-list |
278 sed 's_/usr/ports/_ _' | tr -d '\n')
280 *) echo "Usage: \`portpkg <build|run>' in a port directory"
288 ll /dev/mixer /dev/sound /dev/audio
291 for x in mixer sound audio; do
292 ln -sf /dev/$x"$1" /dev/$x
297 for x in $(mixerctl -a | grep 'outputs\.master'); do
302 mixerctl -w outputs.master"$2"="$1"
306 # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance
313 zstyle ':vcs_info:*' enable git
314 #zstyle ':vcs_info:git*' check-for-changes true #too slow
315 zstyle ':vcs_info:git*:dotfiles' check-for-changes true
316 zstyle ':vcs_info:git*' check-for-staged-changes true
317 autoload -Uz vcs_info
320 zstyle ':completion:*' auto-description '[arg] %d'
321 zstyle ':completion:*' expand suffix
322 zstyle ':completion:*' format '# %d'
323 zstyle ':completion:*' group-name ''
324 zstyle ':completion:*' ignore-parents parent
325 zstyle ':completion:*' insert-unambiguous false
326 zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
327 zstyle ':completion:*' list-prompt '%B%i%b'
328 zstyle ':completion:*' list-suffixes true
329 zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
330 zstyle ':completion:*' menu select=1
331 zstyle ':completion:*' original false
332 zstyle ':completion:*' select-prompt '%B%l%b'
333 zstyle ':completion:*' verbose true
334 autoload -Uz compinit && compinit
337 # do this last so prompt can potentially override other settings
338 autoload -Uz promptinit && promptinit
341 ### load site-specific
342 if [[ -f ~/.zprofile.local ]] { source ~/.zprofile.local }
345 unfunction check-busybox
347 # vim: set et sts=4 sw=4 ts=8 tw=79 :