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