X-Git-Url: https://git.sev.monster/~sev/dotfiles.git/blobdiff_plain/57f9ed7a8fc80250bae6c6d0b48d68b64a677563..bad470a88fc3b9009d1273eaee544685e385c00d:/etc/zsh/.zshrc diff --git a/etc/zsh/.zshrc b/etc/zsh/.zshrc index 46c1992..d71861e 100644 --- a/etc/zsh/.zshrc +++ b/etc/zsh/.zshrc @@ -10,8 +10,9 @@ setopts=( ## 16.2.4 History # NOTE: NO_HIST_SAVE_BY_COPY to allow saving histfile if updating another # user's histfile. this is for compatibility with zsu. - HIST_FCNTL_LOCK HIST_IGNORE_DUPS HIST_IGNORE_SPACE HIST_LEX_WORDS - HIST_NO_STORE HIST_REDUCE_BLANKS NO_HIST_SAVE_BY_COPY SHARE_HISTORY + EXTENDED_HISTORY HIST_FCNTL_LOCK HIST_IGNORE_ALL_DUPS HIST_IGNORE_DUPS + HIST_IGNORE_SPACE HIST_LEX_WORDS HIST_NO_STORE HIST_REDUCE_BLANKS + NO_HIST_SAVE_BY_COPY HIST_SAVE_NO_DUPS SHARE_HISTORY ## 16.2.6 Input/Output NO_CLOBBER CLOBBER_EMPTY CORRECT_ALL INTERACTIVE_COMMENTS HASH_EXECUTABLES_ONLY @@ -142,12 +143,16 @@ if [[ ! -v _sev_force_zkbd && ( -v terminfo || -v termcap ) ]] { } find_keymap if [[ -z $keymap ]] { - if read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]"; then + if (read -q "?Can't read terminfo. Add new zkbd keymap? [y/N]") { echo - autoload -Uz zkbd && zkbd - unfunction zkbd + { + autoload -Uz zkbd && zkbd + } always { + TRY_BLOCK_ERROR=0 + unfunction zkbd + } find_keymap - fi + } echo } if [[ -n $keymap ]] { @@ -200,6 +205,39 @@ for k v (${(kv)a}) { } unset a k v +## fzf +# bash-style reverse-search-history (i.e. reverse-i-search) +if [[ -v commands[fzf] ]] { + function _history-incremental-pattern-search-fzf { + fc -AI + # XXX: this shit is cursed and sometimes doesn't work + # TODO: remove doesn't work over newlines, fzf replaces them with \n, + # and sed of course hates newlines and would need to be massaged + # TODO: interactive history refresh... can't get zsh to load histfile: + # +reload(HISTFILE='"$h HISTSIZE=$HISTSIZE SAVEHIST=$SAVEHIST \$0 +Z -dfimc 'setopt EXTENDED_HISTORY;fc -R \$HISTFILE;$c' &1)" \ + local c='fc -lt%F -1 0' + local h="'${HISTFILE//\'/\'\\\'\'}'" + local l=(${(f)"$($=c | fzf \ + --scheme=history -e -n 1,3.. \ + +s \ + -m --bind 'ctrl-d:execute-silent(sed -i -f <( + sed -Ee '\''s/[$*.[\^/]/\\&/g;s~.*~/^\\(: [0-9]\\+:[0-9]\\+;\\)\\?&$/d~'\'' {+f3..} + ) '$h')+abort' \ + --preview-window=hidden --height=20% \ + --with-shell "${0:a} -dfc" \ + ${BUFFER:+-q $BUFFER})"}) + # XXX: this sucks, I hate this. no other way to flush internal history? + HISTFILE= HISTSIZE=0 fc -p $HISTFILE $HISTSIZE $SAVEHIST + l=$(for x ("${l[@]}") { echo ${${=x}:3}; }) + BUFFER="$l" + zle reset-prompt + } + zle -N _history-incremental-pattern-search-fzf + bindkey '^R' _history-incremental-pattern-search-fzf +} else { + bindkey '^R' history-incremental-pattern-search-backward +} + ### aliases ## builtins alias rehash='_sev_setpath; rehash' @@ -276,6 +314,7 @@ alias svu="sudo python3 -mvenv --upgrade" alias g=git alias gd='git diff' alias gdh='git diff HEAD' +alias gdp='git diff HEAD\^' alias gds='git diff --staged' alias ga='git add' alias ga.='git add .' @@ -287,9 +326,15 @@ alias gp='git push' alias gu='git pull' alias gl='git log' alias gt='git tree' # from gitconfig -alias gs='git show' -alias gst='git stash' +alias gsh='git show' +alias gshn='git show --name-status' +alias gst='git status' +alias gsts='git status --short' +alias gs='git stash' alias gsp='git stash pop' +alias gsd='git stash drop' +alias gss='git stash show -p' +alias grc='git rebase --continue' ## cd/zoxide function up { \cd $(printf '../%.0s' {1..${1:-1}}) @@ -299,6 +344,7 @@ if [[ -v commands[zoxide] ]] { # https://github.com/ajeetdsouza/zoxide/issues/513 eval "${$(zoxide init zsh):s#_files -/#_cd#}" alias cd=z + alias z-='z -' } alias cd..=up ## dotfiles @@ -351,61 +397,12 @@ function sev_chpwd { } add-zsh-hook chpwd sev_chpwd -### system-specific configs and aliases -case $OSTYPE; in - freebsd*) - ## colors - export CLICOLOR= - export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30' - - ## sound - function s { sysctl hw.snd.default_unit${1:+\=$1} } - alias vol mixer - - ## install port dependencies from pkg (like pkgsrc `bmake bin-install') - # XXX: should probably use package-depends where possible, breaks when - # port name is different to package name - # (eg. graphics/sdl20 == sdl2, devel/glib20 == glib2, etc) - function portpkg { - case "$1" { - build|run) - sudo pkg install -AU $(make ${1}-depends-list | - sed 's_/usr/ports/_ _' | tr -d '\n') - ;; - *) echo "Usage: \`portpkg ' in a port directory" - return 1;; - } - };; - netbsd) - ## sound - function s { - if [[ -z "$1" ]] { - ll /dev/mixer /dev/sound /dev/audio - return - } - for x in mixer sound audio; do - ln -sf /dev/$x"$1" /dev/$x - done - } - function vol { - if [[ -z "$1" ]] { - for x in $(mixerctl -a | grep 'outputs\.master'); do - echo -E - $x - done - return - } - mixerctl -w outputs.master"$2"="$1" - };; - *) - ## sound - # TODO: test alsa/oss/sndio/portaudio/pulse/pipewire in order of importance - function s {} - function vol {} -esac - ### prompt autoload -Uz promptinit && promptinit prompt arrows +### plugins +load-plugins zshrc + ### load site-specific load-site-dotfile zshrc