]> git.sev.monster Git - dotfiles.git/blame - base/.zshrc
fix .zshenv syntax on last commit
[dotfiles.git] / base / .zshrc
CommitLineData
abd1eae8 1### imports
2source ~/bin/.check-busybox
3
fab483dd 4### user-local fpath
5fpath=(~/.zsh ~/.zsh/functions/Prompts "${fpath[@]}")
6
d877aef2 7### options
186423fe 8setopt NO_BEEP NO_CLOBBER
9## cd
10setopt AUTO_CD CDABLE_VARS
11## completion
12setopt GLOB_COMPLETE
13## line
14setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT
15## prompt
16setopt PROMPT_SUBST
17## jobs
18setopt AUTO_CONTINUE
19## history
20setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY
12f46d4e 21HISTFILE=~/.histfile
186423fe 22HISTSIZE=1000
23SAVEHIST=1000
12f46d4e 24
d877aef2 25### keys
12f46d4e 26bindkey -v
e8abe786 27KEYTIMEOUT=1
d877aef2 28## xorg
12f46d4e 29bindkey "^[[7~" beginning-of-line #Home
30bindkey -a "^[[7~" beginning-of-line
31bindkey "^[[8~" end-of-line #End
32bindkey -a "^[[8~" end-of-line
33bindkey "^[[3~" delete-char #Del
34bindkey -a "^[[3~" delete-char
d877aef2 35## history search
fab483dd 36autoload -Uz up-line-or-beginning-search down-line-or-beginning-search && {
4f471013 37 if [[ -n "$key[Up]" ]] {
fab483dd 38 zle -N up-line-or-beginning-search
39 bindkey -- "$key[Up]" up-line-or-beginning-search
40 }
41 if [[ -n "$key[Down]" ]] {
42 bindkey -- "$key[Down]" down-line-or-beginning-search
43 zle -N down-line-or-beginning-search
44 }
45}
12f46d4e 46
d877aef2 47### aliases
1b8a4102 48alias h="history -25"
49alias j="jobs -l"
e8abe786 50alias l="ls -AF"
fab483dd 51alias e="${EDITOR:-vi}" # TODO: make sure vi is there or use safe default
dcac60d9 52if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] {
53 alias ll="ls -lAFho"
54} else {
55 alias ll="ls -lAFh"
56}
cd5c7e1d 57alias se=sudoedit
d877aef2 58## ps
fab483dd 59local p=
4f471013 60if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then
fab483dd 61 # use pstree, but NOT busybox pstree because it kinda sucks
dcac60d9 62 p="pstree -wg3"
4f471013 63elif [[ "$OSTYPE" =~ '^freebsd' ]]; then
dcac60d9 64 p="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
65 -o%cpu,%mem,tty,stat,start=START -oetime,command"
4f471013 66elif check-busybox ps; then
dcac60d9 67 # busybox compatible
68 p="ps -eouser='USR ' -ogroup='GRP ' \
69 -opid=' PID' -onice=' NI' -ovsz=' MEM' \
70 -otty,stat,etime,comm"
4f471013 71else
dcac60d9 72 # XXX: untested, posix
73 # TODO: support gnu ps
74 p="ps -eouser=USR -ogroup=GRP -opid,nice=NI \
75 -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm"
4f471013 76fi
77if [[ "$(basename "$PAGER")" = "less" ]] {
78 p="$p | less -SE"
79} else {
80 p="$p | \"${PAGER:-more}\""
dcac60d9 81}
e8abe786 82alias pa="$p"
83alias spa="sudo $p"
84unset p
d877aef2 85## py venv
3edfaacd 86alias va="source bin/activate"
ab4fdc87 87alias vd="deactivate"
d877aef2 88## be paranoid
1b8a4102 89alias cp='cp -ip'
90alias mv='mv -i'
ff1a2414 91if [[ "$OSTYPE" =~ '^freebsd' ]] {
d877aef2 92 # don't confirm if only a few files are deleted
93 alias rm='rm -I'
94} else {
fab483dd 95 # TODO: similar behavior for non-freebsd, or impliment in zsh
d877aef2 96 alias rm='rm -i'
118fb6e0 97}
fab483dd 98## go up directories
99function up() {
100 cd $(printf '../%.0s' {1..${1:-1}})
e8abe786 101}
4ebae5dc 102
d877aef2 103### hooks
ff1a2414 104local _exectime=
e8abe786 105function precmd {
26a611b7 106 # change terminal title
fab483dd 107 # TODO: update and send BEL when job status changes
d877aef2 108 print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\"
26a611b7 109 # bell if exec takes 5s
110 if ((SECONDS - _exectime >= 5)) print "\a"
fab483dd 111 # we could update vcs_info here, but let prompt take care of it
112 # if it doesn't use vcs, it can be ignored safely
e8abe786 113}
114function preexec {
26a611b7 115 # change terminal title to show command
d877aef2 116 print -Pnf "\e]2;%s\e\\" "%#${SSH_CLIENT+$USER@$HOST:}$1"
26a611b7 117 # save last exec time for bell
dcac60d9 118 # XXX: does not run for blank cmdline
e8abe786 119 _exectime=$SECONDS
120}
26a611b7 121function chpwd {
dcac60d9 122 # echo dir on cwd change
26a611b7 123 l
124}
e8abe786 125
ff1a2414 126### system-specific configs and aliases
127case "$OSTYPE"; in
128 freebsd*)
129 ## vt binds
130 bindkey "^[[H" beginning-of-line #Home
131 bindkey -a "^[[H" beginning-of-line
132 bindkey "^[[F" end-of-line #End
133 bindkey -a "^[[F" end-of-line
d877aef2 134
ff1a2414 135 ## sound
136 function s { sysctl hw.snd.default_unit${1:+\=$1} }
137 alias vol mixer
d877aef2 138
ff1a2414 139 ## install port dependencies from pkg (like pkgsrc `bmake bin-install')
140 #XXX: should probably use package-depends where possible, breaks when
141 # port name is different to package name
142 # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc)
143 function portpkg {
144 case "$1" {
145 build|run)
146 sudo pkg install -AU $(make ${1}-depends-list |
147 sed 's_/usr/ports/_ _' | tr -d '\n')
148 ;;
149 *) echo "Usage: \`portpkg <build|run>' in a port directory"
150 return 1;;
151 }
152 };;
153 netbsd)
154 ## sound
155 function s {
156 if [[ -z "$1" ]] {
157 ll /dev/mixer /dev/sound /dev/audio
158 return
159 }
160 for x in mixer sound audio; do
161 ln -sf /dev/$x"$1" /dev/$x
162 done
d877aef2 163 }
ff1a2414 164 function vol {
165 if [[ -z "$1" ]] {
166 for x in $(mixerctl -a | grep 'outputs\.master'); do
167 echo $x
168 done
169 return
170 }
171 mixerctl -w outputs.master"$2"="$1"
172 };;
dcac60d9 173 *)
174 ## sound
175 # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance
fab483dd 176 function s() {}
abd1eae8 177 function vol() {}
ff1a2414 178esac
d877aef2 179
fab483dd 180### modules & styles
181## vcs
182autoload -Uz vcs_info
183zstyle ':vcs_info:*' enable git
184#zstyle ':vcs_info:git*' check-for-changes true #too slow
185zstyle ':vcs_info:git*:dotfiles' check-for-changes true
186zstyle ':vcs_info:git*' check-for-staged-changes true
187
188## compinit
1b8a4102 189# The following lines were added by compinstall
fab483dd 190zstyle ':completion:*' auto-description '[arg] %d'
1b8a4102 191zstyle ':completion:*' expand suffix
192zstyle ':completion:*' format '# %d'
193zstyle ':completion:*' group-name ''
194zstyle ':completion:*' ignore-parents parent
195zstyle ':completion:*' insert-unambiguous false
196zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
197zstyle ':completion:*' list-prompt '%B%i%b'
198zstyle ':completion:*' list-suffixes true
199zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
200zstyle ':completion:*' menu select=1
201zstyle ':completion:*' original false
202zstyle ':completion:*' select-prompt '%B%l%b'
203zstyle ':completion:*' verbose true
204zstyle :compinstall filename '/home/ds6/.zshrc'
205
206autoload -Uz compinit
207compinit
208# End of lines added by compinstall
209
fab483dd 210## prompt
211# do this last so prompt can potentially override
212autoload -Uz promptinit && promptinit
4f471013 213prompt arrows
fab483dd 214
abd1eae8 215
216### unset imports
217unfunction check-busybox
218
fab483dd 219# vim: set et sts=4 sw=4 ts=8 tw=79 :
This page took 0.063036 seconds and 4 git commands to generate.