]> git.sev.monster Git - dotfiles.git/blame - base/.zshrc
complete .zshenv silence
[dotfiles.git] / base / .zshrc
CommitLineData
43016843 1### options
2setopt NO_BEEP NO_CLOBBER
3## cd
4setopt AUTO_CD CDABLE_VARS
5## completion
6setopt GLOB_COMPLETE
7## line
8setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT
9## prompt
10setopt PROMPT_SUBST
11## jobs
12setopt AUTO_CONTINUE
13## history
973a2767 14setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY HIST_REDUCE_BLANKS
43016843 15
16### keys
17# TODO: investigate "^[[200~" bracketed-paste
18bindkey -v
19KEYTIMEOUT=10
20## populate key array
21if (( $#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
26 }
27 find_keymap
28 if [[ -z $keymap ]] {
29 if read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]"; then
30 echo
31 autoload -Uz zkbd && zkbd
32 unfunction zkbd
33 find_keymap
34 fi
35 echo
36 }
37 if [[ -n $keymap ]] {
38 source $keymap
39 } else {
c3608beb 40 echo "Failed to source keymap file $keymap" >&2
43016843 41 }
42 unfunction find_keymap; unset keymap
43} else {
44 # activate application mode for zle so terminfo keys work
c3608beb 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
43016843 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
54 }
55 # match zkbd hash as best we can to terminfo
56 typeset -gA key
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?
81}
82
83## bind keys in both viins and vicmd modes
84function multibind {
85 local k=$key[$1]
86 if [[ -n $k ]] {
87 bindkey -- $k $2
88 if [[ -v 3 ]] {
89 # - will use same command as viins
90 bindkey -a -- $k ${3:/-/$2}
91 }
92 }
93}
94multibind Backspace backward-delete-char vi-backward-char
95multibind Insert overwrite-mode vi-insert
96multibind Home beginning-of-line -
97multibind PageUp up-line-or-history -
98multibind Delete delete-char vi-delete-char
99multibind End end-of-line -
100multibind PageDown down-line-or-history -
101multibind Left backward-char vi-backward-char
102multibind Right forward-char vi-forward-char
103## history search
104autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
105zle -N up-line-or-beginning-search
106multibind Up up-line-or-beginning-search -
107zle -N down-line-or-beginning-search
108multibind Down down-line-or-beginning-search -
109unfunction multibind
110
111### aliases
112## generic abbreviations
113alias h="history -25"
114alias j="jobs -l"
115alias l="ls -AF"
116alias p="${PAGER:-more}" # TODO: make sure more is there or use safe default
117alias e="${EDITOR:-vi}" # TODO: make sure vi is there or use safe default
118if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] {
119 alias ll="ls -lAFho"
120} else {
121 alias ll="ls -lAFh"
122}
123alias se=sudoedit
124## be paranoid
125alias cp='cp -ip'
126alias mv='mv -i'
127if [[ "$OSTYPE" =~ '^freebsd' ]] {
128 # don't confirm if only a few files are deleted
129 alias rm='rm -I'
130} else {
131 # TODO: similar behavior for non-freebsd, or impliment in zsh
132 alias rm='rm -i'
133}
134## go up directories
135function up {
136 cd $(printf '../%.0s' {1..${1:-1}})
137}
138## py venv
139alias va="source bin/activate"
140alias vd="deactivate"
141## ps
142# source helper function
143source ~/bin/.check-busybox
144if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then
145 # use pstree, but NOT busybox pstree because it kinda sucks
146 ps="pstree -wg3"
147elif [[ "$OSTYPE" =~ '^freebsd' ]]; then
148 ps="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
149 -o%cpu,%mem,tty,stat,start=START -oetime,command"
150elif check-busybox ps; then
151 # busybox compatible
152 ps="ps -eouser='USR ' -ogroup='GRP ' \
153 -opid=' PID' -onice=' NI' -ovsz=' MEM' \
154 -otty,stat,etime,comm"
155else
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"
160fi
161unfunction check-busybox
162if [[ "$(basename "$PAGER")" = "less" ]] {
163 ps="$ps | less -SE"
164} else {
165 ps="$ps | \"${PAGER:-more}\""
166}
167alias pa="$ps"
168alias spa="sudo $ps"
169unset ps
170
171### hooks
172autoload -Uz add-zsh-hook
173_sev_exectime=
174function 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
180}
181add-zsh-hook preexec sev_preexec
182function 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
190}
191add-zsh-hook precmd sev_precmd
192function sev_chpwd {
193 # echo dir on cwd change
194 ls -AF
195}
196add-zsh-hook chpwd sev_chpwd
197
198### system-specific configs and aliases
199case "$OSTYPE"; in
200 freebsd*)
201 # colors
202 export CLICOLOR=
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'
204
205 ## sound
206 function s { sysctl hw.snd.default_unit${1:+\=$1} }
207 alias vol mixer
208
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)
213 function portpkg {
214 case "$1" {
215 build|run)
216 sudo pkg install -AU $(make ${1}-depends-list |
217 sed 's_/usr/ports/_ _' | tr -d '\n')
218 ;;
219 *) echo "Usage: \`portpkg <build|run>' in a port directory"
220 return 1;;
221 }
222 };;
223 netbsd)
224 ## sound
225 function s {
226 if [[ -z "$1" ]] {
227 ll /dev/mixer /dev/sound /dev/audio
228 return
229 }
230 for x in mixer sound audio; do
231 ln -sf /dev/$x"$1" /dev/$x
232 done
233 }
234 function vol {
235 if [[ -z "$1" ]] {
236 for x in $(mixerctl -a | grep 'outputs\.master'); do
237 echo $x
238 done
239 return
240 }
241 mixerctl -w outputs.master"$2"="$1"
242 };;
243 *)
244 ## sound
245 # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance
246 function s {}
247 function vol {}
248esac
249
250### modules & styles
251## vcs
252zstyle ':vcs_info:*' enable git
253#zstyle ':vcs_info:git*' check-for-changes true #too slow
254zstyle ':vcs_info:git*:dotfiles' check-for-changes true
255zstyle ':vcs_info:git*' check-for-staged-changes true
256autoload -Uz vcs_info
257
258## compinit
259zstyle ':completion:*' auto-description '[arg] %d'
260zstyle ':completion:*' expand suffix
261zstyle ':completion:*' format '# %d'
262zstyle ':completion:*' group-name ''
263zstyle ':completion:*' ignore-parents parent
264zstyle ':completion:*' insert-unambiguous false
265zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
266zstyle ':completion:*' list-prompt '%B%i%b'
267zstyle ':completion:*' list-suffixes true
268zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
269zstyle ':completion:*' menu select=1
270zstyle ':completion:*' original false
271zstyle ':completion:*' select-prompt '%B%l%b'
272zstyle ':completion:*' verbose true
273autoload -Uz compinit && compinit
274
275### prompt
276autoload -Uz promptinit && promptinit
277prompt arrows
278
8eb81f95 279### load site-specific
280if [[ -f ~/.zshrc.local ]] { source ~/.zshrc.local }
abd1eae8 281
fab483dd 282# vim: set et sts=4 sw=4 ts=8 tw=79 :
This page took 0.067573 seconds and 4 git commands to generate.