mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-19 00:53:42 -05:00
re-wrote and simplified history search script
30
Examples.md
30
Examples.md
@@ -173,11 +173,11 @@ fh() {
|
||||
}
|
||||
```
|
||||
|
||||
Replacing `eval` with `print -z` will push the arguments onto the editing buffer stack, allowing you to edit the command before running it. It also means the command you run will appear in your history rather than just `fh`. Unfortunately this only works for zsh.
|
||||
Replacing `eval` with `print -z` will push the arguments onto the editing buffer stack, allowing you to edit the command before running it. It also means the command you run will appear in your history rather than just `fh`. Unfortunately this only works for zsh. See below for solutions working with Bash.
|
||||
|
||||
#### With write to terminal capabilities
|
||||
|
||||
These have been tested in bash.
|
||||
These have been tested in bash.
|
||||
|
||||
```sh
|
||||
# fh - repeat history
|
||||
@@ -234,6 +234,32 @@ builtin bind -x '"\C-x1": __fzf_history';
|
||||
builtin bind '"\C-r": "\C-x1\e^\er"'
|
||||
```
|
||||
|
||||
```sh
|
||||
# re-wrote the script above
|
||||
bind '"\C-r": "\C-x1\e^\er"'
|
||||
bind -x '"\C-x1": __fzf_history';
|
||||
|
||||
__fzf_history ()
|
||||
{
|
||||
__ehc $(history | fzf --tac --tiebreak=index | perl -ne 'm/^\s*([0-9]+)/ and print "!$1"')
|
||||
}
|
||||
|
||||
__ehc()
|
||||
{
|
||||
if
|
||||
[[ -n $1 ]]
|
||||
then
|
||||
bind '"\er": redraw-current-line'
|
||||
bind '"\e^": magic-space'
|
||||
READLINE_LINE=${READLINE_LINE:+${READLINE_LINE:0:READLINE_POINT}}${1}${READLINE_LINE:+${READLINE_LINE:READLINE_POINT}}
|
||||
READLINE_POINT=$(( READLINE_POINT + ${#1} ))
|
||||
else
|
||||
bind '"\er":'
|
||||
bind '"\e^":'
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
### Toggle options
|
||||
|
||||
```sh
|
||||
|
||||
Reference in New Issue
Block a user