]> git.sev.monster Git - dotfiles.git/blame - base/.zshrc
partially revert zsh refactor, fix zsh conf bugs
[dotfiles.git] / base / .zshrc
CommitLineData
3c83c67b 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
14setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY
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 {
40 echo "Failed to source file $keymap" >&2
41 }
42 unfunction find_keymap; unset keymap
43} else {
44 # activate application mode for zle so terminfo keys work
45 # don't do this for zkbd since application mode shouldn't have ben enabled
46 if [[ -v terminfo[smkx] && -v terminfo[rmkx] ]] {
47 autoload -Uz add-zle-hook-widget
48 function _enter-application-mode { echoti smkx }
49 add-zle-hook-widget line-init _enter-application-mode
50 function _exit-application-mode { echoti rmkx }
51 add-zle-hook-widget line-finish _exit-application-mode
52 trap _exit-application-mode EXIT
53 }
54 # match zkbd hash as best we can to terminfo
55 typeset -gA key
56 key[F1]=$terminfo[kf1]
57 key[F2]=$terminfo[kf2]
58 key[F3]=$terminfo[kf3]
59 key[F4]=$terminfo[kf4]
60 key[F5]=$terminfo[kf5]
61 key[F6]=$terminfo[kf6]
62 key[F7]=$terminfo[kf7]
63 key[F8]=$terminfo[kf8]
64 key[F9]=$terminfo[kf9]
65 key[F10]=$terminfo[kf10]
66 key[F11]=$terminfo[kf11]
67 key[F12]=$terminfo[kf12]
68 key[Backspace]=$terminfo[kbs]
69 key[Insert]=$terminfo[kich1]
70 key[Home]=$terminfo[khome]
71 key[PageUp]=$terminfo[kpp]
72 key[Delete]=$terminfo[kdch1]
73 key[End]=$terminfo[kend]
74 key[PageDown]=$terminfo[knp]
75 key[Up]=$terminfo[kcuu1]
76 key[Down]=$terminfo[kcud1]
77 key[Left]=$terminfo[kcub1]
78 key[Right]=$terminfo[kcuf1]
79 #key[Menu]=$terminfo[] #TODO: not in termcap?
80}
81
82## bind keys in both viins and vicmd modes
83function multibind {
84 local k=$key[$1]
85 if [[ -n $k ]] {
86 bindkey -- $k $2
87 if [[ -v 3 ]] {
88 # - will use same command as viins
89 bindkey -a -- $k ${3:/-/$2}
90 }
91 }
92}
93multibind Backspace backward-delete-char vi-backward-char
94multibind Insert overwrite-mode vi-insert
95multibind Home beginning-of-line -
96multibind PageUp up-line-or-history -
97multibind Delete delete-char vi-delete-char
98multibind End end-of-line -
99multibind PageDown down-line-or-history -
100multibind Left backward-char vi-backward-char
101multibind Right forward-char vi-forward-char
102## history search
103autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
104zle -N up-line-or-beginning-search
105multibind Up up-line-or-beginning-search -
106zle -N down-line-or-beginning-search
107multibind Down down-line-or-beginning-search -
108unfunction multibind
109
110### aliases
111## generic abbreviations
112alias h="history -25"
113alias j="jobs -l"
114alias l="ls -AF"
115alias p="${PAGER:-more}" # TODO: make sure more is there or use safe default
116alias e="${EDITOR:-vi}" # TODO: make sure vi is there or use safe default
117if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] {
118 alias ll="ls -lAFho"
119} else {
120 alias ll="ls -lAFh"
121}
122alias se=sudoedit
123## be paranoid
124alias cp='cp -ip'
125alias mv='mv -i'
126if [[ "$OSTYPE" =~ '^freebsd' ]] {
127 # don't confirm if only a few files are deleted
128 alias rm='rm -I'
129} else {
130 # TODO: similar behavior for non-freebsd, or impliment in zsh
131 alias rm='rm -i'
132}
133## go up directories
134function up {
135 cd $(printf '../%.0s' {1..${1:-1}})
136}
137## py venv
138alias va="source bin/activate"
139alias vd="deactivate"
140## ps
141# source helper function
142source ~/bin/.check-busybox
143if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then
144 # use pstree, but NOT busybox pstree because it kinda sucks
145 ps="pstree -wg3"
146elif [[ "$OSTYPE" =~ '^freebsd' ]]; then
147 ps="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
148 -o%cpu,%mem,tty,stat,start=START -oetime,command"
149elif check-busybox ps; then
150 # busybox compatible
151 ps="ps -eouser='USR ' -ogroup='GRP ' \
152 -opid=' PID' -onice=' NI' -ovsz=' MEM' \
153 -otty,stat,etime,comm"
154else
155 # XXX: untested, posix
156 # TODO: support gnu ps
157 ps="ps -eouser=USR -ogroup=GRP -opid,nice=NI \
158 -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm"
159fi
160unfunction check-busybox
161if [[ "$(basename "$PAGER")" = "less" ]] {
162 ps="$ps | less -SE"
163} else {
164 ps="$ps | \"${PAGER:-more}\""
165}
166alias pa="$ps"
167alias spa="sudo $ps"
168unset ps
169
170### hooks
171autoload -Uz add-zsh-hook
172_sev_exectime=
173function sev_preexec {
174 # change terminal title to show command
175 print -n "\e]2;$(print -P '%#')${SSH_CLIENT+$USER@$HOST:}$1\e\\"
176 # save last exec time for bell
177 # XXX: does not run for blank cmdline
178 _sev_exectime=$SECONDS
179}
180add-zsh-hook preexec sev_preexec
181function sev_precmd {
182 # change terminal title
183 # TODO: update and send BEL when job status changes
184 print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\"
185 # bell if exec takes 5s
186 if (( SECONDS - _sev_exectime >= 5 )) print "\a"
187 # we could update vcs_info here, but let prompt take care of it
188 # if it doesn't use vcs, it can be ignored safely
189}
190add-zsh-hook precmd sev_precmd
191function sev_chpwd {
192 # echo dir on cwd change
193 ls -AF
194}
195add-zsh-hook chpwd sev_chpwd
196
197### system-specific configs and aliases
198case "$OSTYPE"; in
199 freebsd*)
200 # colors
201 export CLICOLOR=
202 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'
203
204 ## sound
205 function s { sysctl hw.snd.default_unit${1:+\=$1} }
206 alias vol mixer
207
208 ## install port dependencies from pkg (like pkgsrc `bmake bin-install')
209 # XXX: should probably use package-depends where possible, breaks when
210 # port name is different to package name
211 # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc)
212 function portpkg {
213 case "$1" {
214 build|run)
215 sudo pkg install -AU $(make ${1}-depends-list |
216 sed 's_/usr/ports/_ _' | tr -d '\n')
217 ;;
218 *) echo "Usage: \`portpkg <build|run>' in a port directory"
219 return 1;;
220 }
221 };;
222 netbsd)
223 ## sound
224 function s {
225 if [[ -z "$1" ]] {
226 ll /dev/mixer /dev/sound /dev/audio
227 return
228 }
229 for x in mixer sound audio; do
230 ln -sf /dev/$x"$1" /dev/$x
231 done
232 }
233 function vol {
234 if [[ -z "$1" ]] {
235 for x in $(mixerctl -a | grep 'outputs\.master'); do
236 echo $x
237 done
238 return
239 }
240 mixerctl -w outputs.master"$2"="$1"
241 };;
242 *)
243 ## sound
244 # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance
245 function s {}
246 function vol {}
247esac
248
249### modules & styles
250## vcs
251zstyle ':vcs_info:*' enable git
252#zstyle ':vcs_info:git*' check-for-changes true #too slow
253zstyle ':vcs_info:git*:dotfiles' check-for-changes true
254zstyle ':vcs_info:git*' check-for-staged-changes true
255autoload -Uz vcs_info
256
257## compinit
258zstyle ':completion:*' auto-description '[arg] %d'
259zstyle ':completion:*' expand suffix
260zstyle ':completion:*' format '# %d'
261zstyle ':completion:*' group-name ''
262zstyle ':completion:*' ignore-parents parent
263zstyle ':completion:*' insert-unambiguous false
264zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
265zstyle ':completion:*' list-prompt '%B%i%b'
266zstyle ':completion:*' list-suffixes true
267zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
268zstyle ':completion:*' menu select=1
269zstyle ':completion:*' original false
270zstyle ':completion:*' select-prompt '%B%l%b'
271zstyle ':completion:*' verbose true
272autoload -Uz compinit && compinit
273
274### prompt
275autoload -Uz promptinit && promptinit
276prompt arrows
277
81c3957e 278### load site-specific
279if [[ -f ~/.zshrc.local ]] { source ~/.zshrc.local }
b3de8395 280
1f53b630 281# vim: set et sts=4 sw=4 ts=8 tw=79 :
This page took 0.084684 seconds and 4 git commands to generate.