X-Git-Url: https://git.sev.monster/~sev/dotfiles.git/blobdiff_plain/73492710f1e10cb89b2d5bb9db8e58b729f4081e..ec83dc0c32145411905204309a6eadfbfa3e17b3:/base/.zshrc?ds=inline diff --git a/base/.zshrc b/base/.zshrc index c5e4093..0da8429 100644 --- a/base/.zshrc +++ b/base/.zshrc @@ -54,74 +54,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,15 +135,10 @@ 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" ## ps -# source helper function source ~/bin/.check-busybox if which pstree >/dev/null 2>&1 && ! check-busybox pstree; then # use pstree, but NOT busybox pstree because it kinda sucks @@ -160,7 +159,7 @@ else fi unfunction check-busybox if [[ "$(basename "$PAGER")" = "less" ]] { - ps="$ps | less -SE" + ps="$ps | less -S" } else { ps="$ps | \"${PAGER:-more}\"" } @@ -168,6 +167,14 @@ alias pa="$ps" alias spa="sudo $ps" unset ps +### specialized aliases +## go up directories +function up { + cd $(printf '../%.0s' {1..${1:-1}}) +} +## zoxide +[[ -v commands[zoxide] ]] && eval "$(zoxide init zsh)" + ### hooks autoload -Uz add-zsh-hook _sev_exectime=