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