]>
Commit | Line | Data |
---|---|---|
b3de8395 | 1 | ### imports |
2 | source ~/bin/.check-busybox | |
3 | ||
1f53b630 | 4 | ### user-local fpath |
5 | fpath=(~/.zsh ~/.zsh/functions/Prompts "${fpath[@]}") | |
6 | ||
ba63cd01 | 7 | ### options |
a8f1ccaf | 8 | setopt NO_BEEP NO_CLOBBER |
9 | ## cd | |
10 | setopt AUTO_CD CDABLE_VARS | |
11 | ## completion | |
12 | setopt GLOB_COMPLETE | |
13 | ## line | |
14 | setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT | |
15 | ## prompt | |
16 | setopt PROMPT_SUBST | |
17 | ## jobs | |
18 | setopt AUTO_CONTINUE | |
19 | ## history | |
20 | setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY | |
7045a58b | 21 | HISTFILE=~/.histfile |
a8f1ccaf | 22 | HISTSIZE=1000 |
23 | SAVEHIST=1000 | |
7045a58b | 24 | |
ba63cd01 | 25 | ### keys |
7045a58b | 26 | bindkey -v |
b3d0247b | 27 | KEYTIMEOUT=1 |
ba63cd01 | 28 | ## xorg |
7045a58b | 29 | bindkey "^[[7~" beginning-of-line #Home |
30 | bindkey -a "^[[7~" beginning-of-line | |
31 | bindkey "^[[8~" end-of-line #End | |
32 | bindkey -a "^[[8~" end-of-line | |
33 | bindkey "^[[3~" delete-char #Del | |
34 | bindkey -a "^[[3~" delete-char | |
ba63cd01 | 35 | ## history search |
1f53b630 | 36 | autoload -Uz up-line-or-beginning-search down-line-or-beginning-search && { |
d3712462 | 37 | if [[ -n "$key[Up]" ]] { |
1f53b630 | 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 | } | |
7045a58b | 46 | |
ba63cd01 | 47 | ### aliases |
189288f7 | 48 | alias h="history -25" |
49 | alias j="jobs -l" | |
b3d0247b | 50 | alias l="ls -AF" |
1f53b630 | 51 | alias e="${EDITOR:-vi}" # TODO: make sure vi is there or use safe default |
a568f7fa | 52 | if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] { |
53 | alias ll="ls -lAFho" | |
54 | } else { | |
55 | alias ll="ls -lAFh" | |
56 | } | |
55a16ad2 | 57 | alias se=sudoedit |
ba63cd01 | 58 | ## ps |
1f53b630 | 59 | local p= |
d3712462 | 60 | if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then |
1f53b630 | 61 | # use pstree, but NOT busybox pstree because it kinda sucks |
a568f7fa | 62 | p="pstree -wg3" |
d3712462 | 63 | elif [[ "$OSTYPE" =~ '^freebsd' ]]; then |
a568f7fa | 64 | p="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \ |
65 | -o%cpu,%mem,tty,stat,start=START -oetime,command" | |
d3712462 | 66 | elif check-busybox ps; then |
a568f7fa | 67 | # busybox compatible |
68 | p="ps -eouser='USR ' -ogroup='GRP ' \ | |
69 | -opid=' PID' -onice=' NI' -ovsz=' MEM' \ | |
70 | -otty,stat,etime,comm" | |
d3712462 | 71 | else |
a568f7fa | 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" | |
d3712462 | 76 | fi |
77 | if [[ "$(basename "$PAGER")" = "less" ]] { | |
78 | p="$p | less -SE" | |
79 | } else { | |
80 | p="$p | \"${PAGER:-more}\"" | |
a568f7fa | 81 | } |
b3d0247b | 82 | alias pa="$p" |
83 | alias spa="sudo $p" | |
84 | unset p | |
ba63cd01 | 85 | ## py venv |
ce090b98 | 86 | alias va="source bin/activate" |
d7ea63a2 | 87 | alias vd="deactivate" |
ba63cd01 | 88 | ## be paranoid |
189288f7 | 89 | alias cp='cp -ip' |
90 | alias mv='mv -i' | |
f7960c69 | 91 | if [[ "$OSTYPE" =~ '^freebsd' ]] { |
ba63cd01 | 92 | # don't confirm if only a few files are deleted |
93 | alias rm='rm -I' | |
94 | } else { | |
1f53b630 | 95 | # TODO: similar behavior for non-freebsd, or impliment in zsh |
ba63cd01 | 96 | alias rm='rm -i' |
9fddba79 | 97 | } |
1f53b630 | 98 | ## go up directories |
99 | function up() { | |
100 | cd $(printf '../%.0s' {1..${1:-1}}) | |
b3d0247b | 101 | } |
ff1edfa8 | 102 | |
ba63cd01 | 103 | ### hooks |
f7960c69 | 104 | local _exectime= |
b3d0247b | 105 | function precmd { |
8f9c4a17 | 106 | # change terminal title |
1f53b630 | 107 | # TODO: update and send BEL when job status changes |
ba63cd01 | 108 | print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\" |
8f9c4a17 | 109 | # bell if exec takes 5s |
110 | if ((SECONDS - _exectime >= 5)) print "\a" | |
1f53b630 | 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 | |
b3d0247b | 113 | } |
114 | function preexec { | |
8f9c4a17 | 115 | # change terminal title to show command |
ba63cd01 | 116 | print -Pnf "\e]2;%s\e\\" "%#${SSH_CLIENT+$USER@$HOST:}$1" |
8f9c4a17 | 117 | # save last exec time for bell |
a568f7fa | 118 | # XXX: does not run for blank cmdline |
b3d0247b | 119 | _exectime=$SECONDS |
120 | } | |
8f9c4a17 | 121 | function chpwd { |
a568f7fa | 122 | # echo dir on cwd change |
8f9c4a17 | 123 | l |
124 | } | |
b3d0247b | 125 | |
f7960c69 | 126 | ### system-specific configs and aliases |
127 | case "$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 | |
ba63cd01 | 134 | |
f7960c69 | 135 | ## sound |
136 | function s { sysctl hw.snd.default_unit${1:+\=$1} } | |
137 | alias vol mixer | |
ba63cd01 | 138 | |
f7960c69 | 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 | |
ba63cd01 | 163 | } |
f7960c69 | 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 | };; | |
a568f7fa | 173 | *) |
174 | ## sound | |
175 | # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance | |
1f53b630 | 176 | function s() {} |
b3de8395 | 177 | function vol() {} |
f7960c69 | 178 | esac |
ba63cd01 | 179 | |
1f53b630 | 180 | ### modules & styles |
181 | ## vcs | |
182 | autoload -Uz vcs_info | |
183 | zstyle ':vcs_info:*' enable git | |
184 | #zstyle ':vcs_info:git*' check-for-changes true #too slow | |
185 | zstyle ':vcs_info:git*:dotfiles' check-for-changes true | |
186 | zstyle ':vcs_info:git*' check-for-staged-changes true | |
187 | ||
188 | ## compinit | |
189288f7 | 189 | # The following lines were added by compinstall |
1f53b630 | 190 | zstyle ':completion:*' auto-description '[arg] %d' |
189288f7 | 191 | zstyle ':completion:*' expand suffix |
192 | zstyle ':completion:*' format '# %d' | |
193 | zstyle ':completion:*' group-name '' | |
194 | zstyle ':completion:*' ignore-parents parent | |
195 | zstyle ':completion:*' insert-unambiguous false | |
196 | zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} | |
197 | zstyle ':completion:*' list-prompt '%B%i%b' | |
198 | zstyle ':completion:*' list-suffixes true | |
199 | zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' | |
200 | zstyle ':completion:*' menu select=1 | |
201 | zstyle ':completion:*' original false | |
202 | zstyle ':completion:*' select-prompt '%B%l%b' | |
203 | zstyle ':completion:*' verbose true | |
204 | zstyle :compinstall filename '/home/ds6/.zshrc' | |
205 | ||
206 | autoload -Uz compinit | |
207 | compinit | |
208 | # End of lines added by compinstall | |
209 | ||
1f53b630 | 210 | ## prompt |
211 | # do this last so prompt can potentially override | |
212 | autoload -Uz promptinit && promptinit | |
d3712462 | 213 | prompt arrows |
1f53b630 | 214 | |
b3de8395 | 215 | |
216 | ### unset imports | |
217 | unfunction check-busybox | |
218 | ||
1f53b630 | 219 | # vim: set et sts=4 sw=4 ts=8 tw=79 : |