X-Git-Url: https://git.sev.monster/~sev/dotfiles.git/blobdiff_plain/c3608beb1b6da54f2e7b489571b750f582338f9f..6abf57e0f57f57983d91cc31bd7396cb20fa94fa:/base/.zshrc?ds=sidebyside diff --git a/base/.zshrc b/base/.zshrc index 014b039..4ee5000 100644 --- a/base/.zshrc +++ b/base/.zshrc @@ -1,27 +1,45 @@ ### options -setopt NO_BEEP NO_CLOBBER -## cd -setopt AUTO_CD CDABLE_VARS -## completion -setopt GLOB_COMPLETE -## line -setopt EXTENDED_GLOB GLOB_DOTS MARK_DIRS NOMATCH NUMERIC_GLOB_SORT -## prompt -setopt PROMPT_SUBST -## jobs -setopt AUTO_CONTINUE -## history -setopt NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY +setopt NO_BEEP NO_CLOBBER \ + AUTO_CD CDABLE_VARS \ + EXTENDED_GLOB GLOB_DOTS GLOB_STAR_SHORT MARK_DIRS NUMERIC_GLOB_SORT \ + CORRECT_ALL INTERACTIVE_COMMENTS \ + GLOB_COMPLETE \ + AUTO_CONTINUE LONG_LIST_JOBS \ + NO_HIST_SAVE_BY_COPY HIST_IGNORE_DUPS SHARE_HISTORY HIST_REDUCE_BLANKS + +### imports +autoload -Uz zmv +autoload -Uz zmathfunc && zmathfunc + +### exports +## common +export EDITOR=vim +export PAGER=less +## grep +# XXX: deprecated in GNU +export GREP_OPTIONS=--color=auto +## histfile +export HISTFILE=~/.histfile +export HISTSIZE=1000 +export SAVEHIST=1000 +## python +export PYTHONSTARTUP=~/.pythonrc +## wayland/sway +# XXX: only do this if we're actually in wayland, but without a start script +export XDG_SESSION_TYPE=wayland +export QT_QPA_PLATFORM=wayland-egl +export QT_WAYLAND_DISABLE_WINDOWDECORATION=-1 +export SDL_VIDEODRIVER=wayland +export TERMINAL=footclient ### keys -# TODO: investigate "^[[200~" bracketed-paste bindkey -v KEYTIMEOUT=10 ## populate key array if (( $#terminfo == 0 )) { # terminfo is not set or empty function find_keymap { - for f in ${ZDOTDIR:-$HOME}/.zkbd/${TERM}{-${DISPLAY:-${VENDOR}-${OSTYPE}},} + for f in ${ZDOTDIR:-$HOME}/.zkbd/$TERM{-${DISPLAY:-$VENDOR-$OSTYPE},} [[ -f $f ]] && keymap=$f && break } find_keymap @@ -54,74 +72,78 @@ if (( $#terminfo == 0 )) { } # match zkbd hash as best we can to terminfo typeset -gA key - key[F1]=$terminfo[kf1] - key[F2]=$terminfo[kf2] - key[F3]=$terminfo[kf3] - key[F4]=$terminfo[kf4] - key[F5]=$terminfo[kf5] - key[F6]=$terminfo[kf6] - key[F7]=$terminfo[kf7] - key[F8]=$terminfo[kf8] - key[F9]=$terminfo[kf9] - key[F10]=$terminfo[kf10] - key[F11]=$terminfo[kf11] - key[F12]=$terminfo[kf12] - key[Backspace]=$terminfo[kbs] - key[Insert]=$terminfo[kich1] - key[Home]=$terminfo[khome] - key[PageUp]=$terminfo[kpp] - key[Delete]=$terminfo[kdch1] - key[End]=$terminfo[kend] - key[PageDown]=$terminfo[knp] - key[Up]=$terminfo[kcuu1] - key[Down]=$terminfo[kcud1] - key[Left]=$terminfo[kcub1] - key[Right]=$terminfo[kcuf1] - #key[Menu]=$terminfo[] #TODO: not in termcap? + key=(F1 kf1 F2 kf2 F3 kf3 F4 kf4 F5 kf5 F6 kf6 F7 kf7 F8 kf8 F9 kf9 + F10 kf10 F11 kf11 F12 kf12 + Backspace kbs + Backtab kcbt + Shift-Tab kcbt + Insert kich1 + Home khome + PageUp kpp + Delete kdch1 + End kend + PageDown knp + Up kcuu1 + Down kcud1 + Left kcub1 + Right kcuf1 + ) + for k v in ${(kv)key}; do + key[$k]=$terminfo[$v] + done; unset k v } - -## bind keys in both viins and vicmd modes -function multibind { - local k=$key[$1] - if [[ -n $k ]] { - bindkey -- $k $2 - if [[ -v 3 ]] { - # - will use same command as viins - bindkey -a -- $k ${3:/-/$2} - } - } -} -multibind Backspace backward-delete-char vi-backward-char -multibind Insert overwrite-mode vi-insert -multibind Home beginning-of-line - -multibind PageUp up-line-or-history - -multibind Delete delete-char vi-delete-char -multibind End end-of-line - -multibind PageDown down-line-or-history - -multibind Left backward-char vi-backward-char -multibind Right forward-char vi-forward-char -## history search +## load history search autoload -Uz up-line-or-beginning-search down-line-or-beginning-search zle -N up-line-or-beginning-search -multibind Up up-line-or-beginning-search - zle -N down-line-or-beginning-search -multibind Down down-line-or-beginning-search - -unfunction multibind -### aliases -## generic abbreviations -alias h="history -25" -alias j="jobs -l" -alias l="ls -AF" -alias p="${PAGER:-more}" # TODO: make sure more is there or use safe default -alias e="${EDITOR:-vi}" # TODO: make sure vi is there or use safe default +## bind keys in both viins and vicmd modes +typeset -A a +a=( + #key viins vicmd + Backspace 'backward-delete-char vi-backward-char' + Insert 'overwrite-mode vi-insert' + Home 'beginning-of-line' + PageUp 'up-history -' + Delete 'delete-char' + End 'end-of-line' + PageDown 'down-history -' + Up 'up-line-or-beginning-search vi-up-line-or-history' + Down 'down-line-or-beginning-search vi-down-line-or-history' + Left 'backward-char' + Right 'forward-char' +) +for k v in ${(kv)a}; do + k=$key[$k] + if [[ -z "$k" ]] { continue } + v=($=v) + bindkey -- $k $v[1] + if [[ $v[2] == '-' ]] { + # copy viins to vicmd verbatim + bindkey -a -- $k $v[1] + } elif (( $#v != 1 )) { + # set vicmd to any other value + bindkey -a -- $k $v[2] + } else { + # copy viins to vicmd and prepend vi- to it + bindkey -a -- $k vi-$v[1] + } +done +unset a k v + +### abbreviation aliases +alias h='history -25' +alias j='jobs -l' +alias l='ls -AF' if [[ "$OSTYPE" =~ '^(free|net)bsd' ]] { - alias ll="ls -lAFho" + alias ll='ls -lAFho' } else { - alias ll="ls -lAFh" + alias ll='ls -lAFh' } +alias p=${PAGER:-more} # TODO: make sure more is there or use alternate +alias e=${EDITOR:-vi} # TODO: make sure vi is there or use alternate alias se=sudoedit -## be paranoid +# be paranoid alias cp='cp -ip' alias mv='mv -i' if [[ "$OSTYPE" =~ '^freebsd' ]] { @@ -131,17 +153,12 @@ if [[ "$OSTYPE" =~ '^freebsd' ]] { # TODO: similar behavior for non-freebsd, or impliment in zsh alias rm='rm -i' } -## go up directories -function up { - cd $(printf '../%.0s' {1..${1:-1}}) -} ## py venv -alias va="source bin/activate" -alias vd="deactivate" +alias va='source bin/activate' +alias vd=deactivate ## ps -# source helper function source ~/bin/.check-busybox -if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then +if [[ -v commands[pstree] ]] && ! check-busybox pstree; then # use pstree, but NOT busybox pstree because it kinda sucks ps="pstree -wg3" elif [[ "$OSTYPE" =~ '^freebsd' ]]; then @@ -160,14 +177,23 @@ else fi unfunction check-busybox if [[ "$(basename "$PAGER")" = "less" ]] { - ps="$ps | less -SE" + ps="$ps | less -S" } else { ps="$ps | \"${PAGER:-more}\"" } -alias pa="$ps" +alias pa=$ps alias spa="sudo $ps" unset ps +### specialized aliases +## go up directories +function up { + cd $(printf '../%.0s' {1..${1:-1}}) +} +alias u=up +## zoxide +[[ -v commands[zoxide] ]] && eval "$(zoxide init zsh)" + ### hooks autoload -Uz add-zsh-hook _sev_exectime= @@ -177,6 +203,11 @@ function sev_preexec { # save last exec time for bell # XXX: does not run for blank cmdline _sev_exectime=$SECONDS + # update gpg forward, to always have unique filename and avoid clashes + if [[ -v _GNUPG_SOCK_DEST_EXT ]] { + export _GNUPG_SOCK_DEST_EXT=$(date +%s).$RANDOM + export _GNUPG_SOCK_DEST=$_GNUPG_SOCK_DEST_BASE.$_GNUPG_SOCK_DEST_EXT + } } add-zsh-hook preexec sev_preexec function sev_precmd { @@ -196,7 +227,7 @@ function sev_chpwd { add-zsh-hook chpwd sev_chpwd ### system-specific configs and aliases -case "$OSTYPE"; in +case $OSTYPE; in freebsd*) # colors export CLICOLOR= @@ -279,4 +310,4 @@ prompt arrows ### load site-specific if [[ -f ~/.zshrc.local ]] { source ~/.zshrc.local } -# vim: set et sts=4 sw=4 ts=8 tw=79 : +# vim: et sts=4 sw=4 ts=8 tw=79