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