bash: shift-delete to delete history entries during CTRL-R
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #4715
authored by Junegunn Choi · committed by Junegunn Choi · parent b638ff4 · Browse files · 3 files·+71 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+71 added−7 removed
- tests:+44 added−0 removed
- other:+27 added−7 removed
Provenance
- Commit
76efddd- Tree
887bc85- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
b638ff4
3 files changed+71 added−7 removed
modified:shell/key-bindings.bash+24 added-6 removed
75 unmodified lines7677787980818283848586878889909182929394959697988899100901011021031041051061071081091101111121131001141151161171181192 unmodified lines12212312412511112612711312812913013113213313413557 unmodified lines75 unmodified lines FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) ) && printf 'builtin cd -- %q' "$(builtin unset CDPATH && builtin cd -- "$dir" && builtin pwd)"}
__fzf_history_delete() { [[ -s $1 ]] || return
local offsets offsets=($(sort -rnu "$1")) for offset in "${offsets[@]}"; do builtin history -d "$offset" done}
if command -v perl > /dev/null; then __fzf_history__() { local output script local output script deletefile deletefile=$(mktemp) script='BEGIN { getc; $/ = "\n\t"; $HISTCOUNT = $ENV{last_hist} + 1 } s/^[ *]//; s/\n/\n\t/gm; print $HISTCOUNT - $. . "\t$_" if !$seen{$_}++' output=$( set +o pipefail builtin fc -lnr -2147483648 | last_hist=$(HISTTIMEFORMAT='' builtin history 1) command perl -n -l0 -e "$script" | FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,alt-r:toggle-raw --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \ FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,alt-r:toggle-raw --wrap-sign '"$'\t'"↳ ' --highlight-line --bind 'shift-delete:execute-silent(echo {1} >> \"$deletefile\")+exclude' ${FZF_CTRL_R_OPTS-} +m --read0") \ FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE" ) || return ) __fzf_history_delete "$deletefile" command rm -f "$deletefile" [[ -n $output ]] || return READLINE_LINE=$(command perl -pe 's/^\d*\t//' <<< "$output") if [[ -z $READLINE_POINT ]]; then echo "$READLINE_LINE" else READLINE_POINT=0x7fffffff fi }else # awk - fallback for POSIX systems __fzf_history__() { local output script local output script deletefile deletefile=$(mktemp) [[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entries script='function P(b) { ++n; sub(/^[ *]/, "", b); if (!seen[b]++) { printf "%d\t%s%c", '$((BASH_REMATCH + 1))' - n, b, 0 } } NR==1 { b = substr($0, 2); next } /^\t/ { P(b); b = substr($0, 2); next }2 unmodified lines output=$( set +o pipefail builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )* __fzf_exec_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )* FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,alt-r:toggle-raw --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \ FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort,alt-r:toggle-raw --wrap-sign '"$'\t'"↳ ' --highlight-line --bind 'shift-delete:execute-silent(echo {1} >> \"$deletefile\")+exclude' ${FZF_CTRL_R_OPTS-} +m --read0") \ FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE" ) || return ) __fzf_history_delete "$deletefile" command rm -f "$deletefile" [[ -n $output ]] || return READLINE_LINE=${output#*$'\t'} if [[ -z $READLINE_POINT ]]; then echo "$READLINE_LINE" else57 unmodified linesmodified:test/test_shell_integration.rb+44 added
830 unmodified lines831 tmux.send_keys "FZF_TMUX=1 #{Shell.bash}", :Enter832 tmux.prepare833 end834 835+ def test_ctrl_r_delete836+ tmux.prepare837+ tmux.send_keys 'echo to-keep', :Enter838+ tmux.prepare839+ tmux.send_keys 'echo to-delete-1', :Enter840+ tmux.prepare841+ tmux.send_keys 'echo to-delete-2', :Enter842+ tmux.prepare843+ tmux.send_keys 'echo another-keeper', :Enter844+ tmux.prepare845+846+ # Open Ctrl-R and delete two entries847+ tmux.send_keys 'C-r'848+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }849+ tmux.send_keys 'to-delete'850+ tmux.until { |lines| assert_equal 2, lines.match_count }851+ # Delete the first match852+ tmux.send_keys 'S-Delete'853+ tmux.until { |lines| assert_equal 1, lines.match_count }854+ # Delete the second match855+ tmux.send_keys 'S-Delete'856+ tmux.until { |lines| assert_equal 0, lines.match_count }857+ # Exit without selecting858+ tmux.send_keys :Escape859+ tmux.prepare860+861+ # Verify deleted entries are gone from history862+ tmux.send_keys 'C-r'863+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }864+ tmux.send_keys 'to-delete'865+ tmux.until { |lines| assert_equal 0, lines.match_count }866+ tmux.send_keys :Escape867+ tmux.prepare868+869+ # Verify kept entries are still there870+ tmux.send_keys 'C-r'871+ tmux.until { |lines| assert_operator lines.match_count, :>, 0 }872+ tmux.send_keys 'to-keep'873+ tmux.until { |lines| assert_equal 1, lines.match_count }874+ tmux.send_keys :Enter875+ tmux.until { |lines| assert_equal 'echo to-keep', lines[-1] }876+ tmux.send_keys 'C-c'877+ end878+879 def test_dynamic_completion_loader880 tmux.paste 'touch /tmp/foo; _fzf_completion_loader=1'881 tmux.paste '_completion_loader() { complete -o default fake; }'882 tmux.paste 'complete -F _fzf_path_completion -o default -o bashdefault fake'218 unmodified linesmodified:CHANGELOG.md+3 added-1 removed
23 unmodified lines24 [8T] baseline: 32.82ms current: 17.79ms (1.84x) matches: 179966 (12.79%)25 ```26 - Improved the cache structure, reducing memory footprint per entry by 86x.27 - With the reduced per-entry cost, the cache now has broader coverage.28+- Shell integration improvements29+ - bash: Press `shift-delete` to delete history entries during CTRL-R search (#4715)28-- fish: Improved command history (CTRL-R) (#4703) (@bitraid)30+ - fish: Improved command history (CTRL-R) (#4703) (@bitraid)31 - `GET /` HTTP endpoint now includes `positions` field in each match entry, providing the indices of matched characters for external highlighting (#4726)32 - Bug fixes33 - `--walker=follow` no longer follows symlinks whose target is an ancestor of the walker root, avoiding severe resource exhaustion when a symlink points outside the tree (e.g. Wine's `z:` → `/`) (#4710)34 - Fixed AWK tokenizer not treating a new line character as whitespace3210 unmodified lines