From 033cd450291d31267a5237f64157f7ae664fd306 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Wed, 15 Dec 2021 12:34:32 +0100 Subject: [PATCH] config/zsh: fix fzf & b on outdated machines --- .config/shell/functions | 5 +++-- .local/bin/scripts/b | 2 +- .zshenv | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.config/shell/functions b/.config/shell/functions index 0dd3b70..ab53836 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -64,7 +64,7 @@ wh() { tool="$(echo "$res" | cut -d' ' -f$(expr 5 '&' "$res" : ".*to \(sudo\|noglob\) " '|' 4) | cut -d'(' -f2)" wh $(test $tool = $1 && echo "-p") $tool # use command which for other shells - else test -r "$res" && b --style=header "$res" || echo "$res" | bat --style=plain --language=sh + else test -r "$res" && b "$res" || echo "$res" | bat --style=plain --language=sh fi } compdef wh=which @@ -80,7 +80,7 @@ pathadd() { } # ZSH completion and stuff {{{1 -alias rs="reset && exec $SHELL" +alias rs="reset && source $HOME/.zshenv && exec $SHELL" alias hist='print -z $(history | tac | fzf --tiebreak=index --bind='"'"'del:execute(sed "\;$(echo {4..})$d" -i.bak $HISTFILE)'"'"' | sed "s|^ \+||" | cut -d" " -f5-)' # Edit shell config files @@ -211,6 +211,7 @@ alias gdiff='git diff --word-diff=color --word-diff-regex=. --no-index' alias grp='grep --color=auto --line-number --ignore-case --binary-files=without-match --directories=skip' grpr() { grp --color=always --recursive $(echo $DIRS_IGNORE | sed 's/-x/--exclude-dir/g') "$@" | less -F; } +grsh() { grpr "$@" $HOME/.{ba,z}sh* $HOME/.local/bin $CONFIG_SHELLS $CONFIG_ZSH } # Recover stray swap files from neovim alias vrec="ls $XDG_DATA_HOME/nvim/swap | sed 's/\%/\//g' | sed 's|\(.*\)\..*|\1|' | head -1 | xargs --no-run-if-empty nvim" diff --git a/.local/bin/scripts/b b/.local/bin/scripts/b index 416d60a..5db0aa1 100755 --- a/.local/bin/scripts/b +++ b/.local/bin/scripts/b @@ -124,7 +124,7 @@ if test "$bat" -o "$batl"; then test "$(bat --version | cut -d. -f2)" -gt 16 && rule=,rule if test $# -gt ${#bat[@]} -a $# -gt ${#batl[@]} && test -z "$args" then $elevate head "${batl[@]}" "${bat[@]}" | cut -c-$(echo "$(tput cols)*1.9" | bc | cut -d. -f1) - else test "$bat" && $elevate bat --style numbers,header$rule --pager 'less -RF' $args "${bat[@]}" + else test "$bat" && $elevate bat --style $(test $# -gt 1 && echo "numbers,")header$rule --pager 'less -RF' $args "${bat[@]}" test "$batl" && $elevate bat --style plain$rule --pager 'less -RF' $args "${batl[@]}" fi fileinfo "${bat[@]}" diff --git a/.zshenv b/.zshenv index a1f5864..887b502 100644 --- a/.zshenv +++ b/.zshenv @@ -85,6 +85,7 @@ export LESS_TERMCAP_se=$'\e[0m' # reset reverse video export LESS_TERMCAP_ue=$'\e[0m' # reset underline export GROFF_NO_SGR=1 # for konsole and gnome-terminal ## fzf defaults +[[ "$(fzf --version 2>/dev/null | grep --only-matching '[0-9]\.[^. ]*')" > 0.24 ]] && _fzf_latest=true || _fzf_latest=false FZF_BINDINGS=$(echo " change:top alt-enter:execute(test -O {} && $EDITOR {} || sudoedit {}) @@ -97,15 +98,14 @@ alt-c:yank alt-w:toggle-preview-wrap alt-j:preview-half-page-down,alt-k:preview-half-page-up shift-down:preview-half-page-down,shift-up:preview-half-page-up -$([[ "$(fzf --version 2>/dev/null | cut -d '.' -f-2)" > 0.24 ]] && echo "alt-shift-down:preview-down,alt-shift-up:preview-up") -esc:close +$($_fzf_latest && echo "alt-shift-down:preview-down,alt-shift-up:preview-up,esc:close") " | xargs -I% echo -n "%," | head -c-1) #alt-r:preview(bat {}), export FZF_HISTDIR="$XDG_STATE_HOME/fzf" mkdir -p "$XDG_STATE_HOME/fzf" export FZF_DEFAULT_OPTS="--select-1 --ansi --marker=o --tiebreak=end,length --history=$FZF_HISTDIR/history --bind='$FZF_BINDINGS' ---preview-window=60%,border-left" +$($_fzf_latest && echo '--preview-window=60%,border-left')" FD_BASE="fd --hidden --color=always --no-ignore-vcs" export FZF_DEFAULT_COMMAND="$FD_BASE --type file" export FZF_CTRL_T_COMMAND="$FD_BASE -d 7"