]> git.sev.monster Git - dotfiles.git/blame - base/.zshrc
update submodules, remove bsd shims, fix bugs
[dotfiles.git] / base / .zshrc
CommitLineData
ba63cd01 1### options
7045a58b 2setopt autocd extendedglob
3unsetopt beep
4
ba63cd01 5### history
7045a58b 6setopt appendhistory
7HISTFILE=~/.histfile
8HISTSIZE=100
9SAVEHIST=100
10
ba63cd01 11### keys
7045a58b 12bindkey -v
b3d0247b 13KEYTIMEOUT=1
ba63cd01 14## xorg
7045a58b 15bindkey "^[[7~" beginning-of-line #Home
16bindkey -a "^[[7~" beginning-of-line
17bindkey "^[[8~" end-of-line #End
18bindkey -a "^[[8~" end-of-line
19bindkey "^[[3~" delete-char #Del
20bindkey -a "^[[3~" delete-char
ba63cd01 21## history search
7045a58b 22autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
23zle -N up-line-or-beginning-search
24zle -N down-line-or-beginning-search
25[[ -n "$key[Up]" ]] && bindkey -- "$key[Up]" up-line-or-beginning-search
26[[ -n "$key[Down]" ]] && bindkey -- "$key[Down]" down-line-or-beginning-search
27
ba63cd01 28### aliases
189288f7 29alias h="history -25"
30alias j="jobs -l"
b3d0247b 31alias l="ls -AF"
a568f7fa 32if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] {
33 alias ll="ls -lAFho"
34} else {
35 alias ll="ls -lAFh"
36}
ba63cd01 37## ps
a568f7fa 38local p=""
39if { which pstree >/dev/null 2>&1 && [[ ! "$(readlink -f $(which pstree))" =~ "/busybox" ]] } {
40 p="pstree -wg3"
41} elif [[ "$OSTYPE" =~ '^freebsd' ]] {
42 p="ps -aSdfxwwouser=USR -ogroup=GRP -opid,nice=NI \
43 -o%cpu,%mem,tty,stat,start=START -oetime,command"
44} elif [[ "$(readlink -f $(which ps))" =~ "/busybox" ]] {
45 # busybox compatible
46 p="ps -eouser='USR ' -ogroup='GRP ' \
47 -opid=' PID' -onice=' NI' -ovsz=' MEM' \
48 -otty,stat,etime,comm"
49} else {
50 # XXX: untested, posix
51 # TODO: support gnu ps
52 p="ps -eouser=USR -ogroup=GRP -opid,nice=NI \
53 -opcpu=CPU -ovsz=MEM -otty,stat,etime,comm"
54}
55p="$p | ${PAGER:-more} -Se"
b3d0247b 56alias pa="$p"
57alias spa="sudo $p"
58unset p
ba63cd01 59## py venv
ce090b98 60alias va="source bin/activate"
d7ea63a2 61alias vd="deactivate"
ba63cd01 62## be paranoid
189288f7 63alias cp='cp -ip'
64alias mv='mv -i'
f7960c69 65if [[ "$OSTYPE" =~ '^freebsd' ]] {
ba63cd01 66 # don't confirm if only a few files are deleted
67 alias rm='rm -I'
68} else {
a568f7fa 69 # TODO: similar behavior for non-freebsd
ba63cd01 70 alias rm='rm -i'
9fddba79 71}
189288f7 72
ba63cd01 73### prompt
b3d0247b 74setopt prompt_subst
a568f7fa 75# DEPR: color reset added to NetBSD in PR/53245, following is not needed for recent releases
76#local f=
c5497cbe 77#XXX: can't think of a way to tell if ssh client is on wscons, just kludge 24/7
78#if [[ "$OSTYPE" = "netbsd" && ( "$TERM" =~ "^wsvt" || "$TERM" =~ '^vt' ) ]] {
79# # fix for wscons
80# f="%F{white}"
81#} else {
a568f7fa 82# f="%f"
c5497cbe 83#}
a568f7fa 84PROMPT='%F{$VICOL}%n%f@%F{$VICOL}%2m%f%(?../%F{red}$?%f)%# '
85RPROMPT='%F{yellow}${vcs_info_msg_0_:-%~}%f %T'
b3d0247b 86
ba63cd01 87## change color based on zle vi mode
b3d0247b 88function zle-line-init zle-keymap-select {
89 VICOL="${${KEYMAP:/vicmd/red}:/(main|viins)/green}"
90 zle reset-prompt
91}
92zle -N zle-line-init
93zle -N zle-keymap-select
94
ba63cd01 95## vcs
b3d0247b 96autoload -Uz vcs_info
97zstyle ':vcs_info:*' enable git
a568f7fa 98zstyle ':vcs_info:git*' formats '%c%u%%F{green}%r/%b%%F{white}/%%F{yellow}%S%%f'
99zstyle ':vcs_info:git*' actionformats '%%F{red}(%a)%f %c%u%%F{green}%r/%b%f/%%F{yellow}%S%f'
ba92616c 100#zstyle ':vcs_info:git*' check-for-changes true #too slow
a568f7fa 101zstyle ':vcs_info:git*:dotfiles' check-for-changes true
ba92616c 102zstyle ':vcs_info:git*' check-for-staged-changes true
103zstyle ':vcs_info:git*' stagedstr "%F{blue}+"
104zstyle ':vcs_info:git*' unstagedstr "%F{red}*"
b3d0247b 105
a568f7fa 106#unset f
ff1edfa8 107
ba63cd01 108### hooks
f7960c69 109local _exectime=
b3d0247b 110function precmd {
8f9c4a17 111 # change terminal title
ba63cd01 112 print -Pn "\e]2;%(1j,%j,)%#${SSH_CLIENT+$USER@$HOST:}%~\e\\"
8f9c4a17 113 # update vcs
b3d0247b 114 vcs_info
8f9c4a17 115 # bell if exec takes 5s
116 if ((SECONDS - _exectime >= 5)) print "\a"
b3d0247b 117}
118function preexec {
8f9c4a17 119 # change terminal title to show command
ba63cd01 120 print -Pnf "\e]2;%s\e\\" "%#${SSH_CLIENT+$USER@$HOST:}$1"
8f9c4a17 121 # save last exec time for bell
a568f7fa 122 # XXX: does not run for blank cmdline
b3d0247b 123 _exectime=$SECONDS
124}
8f9c4a17 125function chpwd {
a568f7fa 126 # echo dir on cwd change
8f9c4a17 127 l
128}
b3d0247b 129
f7960c69 130### system-specific configs and aliases
131case "$OSTYPE"; in
132 freebsd*)
133 ## vt binds
134 bindkey "^[[H" beginning-of-line #Home
135 bindkey -a "^[[H" beginning-of-line
136 bindkey "^[[F" end-of-line #End
137 bindkey -a "^[[F" end-of-line
ba63cd01 138
f7960c69 139 ## sound
140 function s { sysctl hw.snd.default_unit${1:+\=$1} }
141 alias vol mixer
ba63cd01 142
f7960c69 143 ## install port dependencies from pkg (like pkgsrc `bmake bin-install')
144 #XXX: should probably use package-depends where possible, breaks when
145 # port name is different to package name
146 # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc)
147 function portpkg {
148 case "$1" {
149 build|run)
150 sudo pkg install -AU $(make ${1}-depends-list |
151 sed 's_/usr/ports/_ _' | tr -d '\n')
152 ;;
153 *) echo "Usage: \`portpkg <build|run>' in a port directory"
154 return 1;;
155 }
156 };;
157 netbsd)
158 ## sound
159 function s {
160 if [[ -z "$1" ]] {
161 ll /dev/mixer /dev/sound /dev/audio
162 return
163 }
164 for x in mixer sound audio; do
165 ln -sf /dev/$x"$1" /dev/$x
166 done
ba63cd01 167 }
f7960c69 168 function vol {
169 if [[ -z "$1" ]] {
170 for x in $(mixerctl -a | grep 'outputs\.master'); do
171 echo $x
172 done
173 return
174 }
175 mixerctl -w outputs.master"$2"="$1"
176 };;
a568f7fa 177 *)
178 ## sound
179 # TODO: test alsa/oss/sndio/portaudio/pulse in order of importance
f7960c69 180esac
ba63cd01 181
189288f7 182# The following lines were added by compinstall
183zstyle ':completion:*' auto-description 'specify: %d'
184zstyle ':completion:*' expand suffix
185zstyle ':completion:*' format '# %d'
186zstyle ':completion:*' group-name ''
187zstyle ':completion:*' ignore-parents parent
188zstyle ':completion:*' insert-unambiguous false
189zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
190zstyle ':completion:*' list-prompt '%B%i%b'
191zstyle ':completion:*' list-suffixes true
192zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} r:|[._-]=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
193zstyle ':completion:*' menu select=1
194zstyle ':completion:*' original false
195zstyle ':completion:*' select-prompt '%B%l%b'
196zstyle ':completion:*' verbose true
197zstyle :compinstall filename '/home/ds6/.zshrc'
198
199autoload -Uz compinit
200compinit
201# End of lines added by compinstall
202
d9362f34 203# vim: ts=8:sts=4:sw=4:et:tw=79
This page took 0.074988 seconds and 4 git commands to generate.