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