+if [[ "$OSTYPE" =~ '^freebsd' ]] {
+ # don't confirm if only a few files are deleted
+ alias rm='rm -I'
+} else {
+ # TODO: similar behavior for non-freebsd, or impliment in zsh
+ alias rm='rm -i'
+}
+## go up directories
+function up {
+ cd $(printf '../%.0s' {1..${1:-1}})
+}
+## py venv
+alias va="source bin/activate"
+alias vd="deactivate"
+## ps
+# source helper function
+source ~/bin/.check-busybox
+if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then
+ # use pstree, but NOT busybox pstree because it kinda sucks
+ ps="pstree -wg3"
+elif [[ "$OSTYPE" =~ '^freebsd' ]]; then
+ ps="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
+ -o%cpu,%mem,tty,stat,start=START -oetime,command"
+elif check-busybox ps; then
+ # busybox compatible
+ ps="ps -eouser='USR ' -ogroup='GRP ' \
+ -opid=' PID' -onice=' NI' -ovsz=' MEM' \
+ -otty,stat,etime,comm"
+else
+ # XXX: untested, posix
+ # TODO: support gnu ps
+ ps="ps -eouser=USR -ogroup=GRP -opid,nice=NI \
+ -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm"
+fi
+unfunction check-busybox
+if [[ "$(basename "$PAGER")" = "less" ]] {
+ ps="$ps | less -SE"
+} else {
+ ps="$ps | \"${PAGER:-more}\""
+}
+alias pa="$ps"
+alias spa="sudo $ps"
+unset ps
+
+### hooks
+autoload -Uz add-zsh-hook
+_sev_exectime=
+function sev_preexec {
+ # change terminal title to show command
+ print -n "\e]2;$(print -P '%#')${SSH_CLIENT+$USER@$HOST:}$1\e\\"
+ # save last exec time for bell
+ # XXX: does not run for blank cmdline
+ _sev_exectime=$SECONDS
+}
+add-zsh-hook preexec sev_preexec
+function sev_precmd {
+ # change terminal title
+ # TODO: update and send BEL when job status changes
+ print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\"
+ # bell if exec takes 5s
+ if (( SECONDS - _sev_exectime >= 5 )) print "\a"
+ # we could update vcs_info here, but let prompt take care of it
+ # if it doesn't use vcs, it can be ignored safely
+}
+add-zsh-hook precmd sev_precmd
+function sev_chpwd {
+ # echo dir on cwd change
+ ls -AF
+}
+add-zsh-hook chpwd sev_chpwd