diff options
Diffstat (limited to 'home-config/fish/functions/_fzf_search_history.fish')
-rw-r--r-- | home-config/fish/functions/_fzf_search_history.fish | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/home-config/fish/functions/_fzf_search_history.fish b/home-config/fish/functions/_fzf_search_history.fish new file mode 100644 index 0000000..cafbce9 --- /dev/null +++ b/home-config/fish/functions/_fzf_search_history.fish | |||
@@ -0,0 +1,39 @@ | |||
1 | function _fzf_search_history --description "Search command history. Replace the command line with the selected command." | ||
2 | # history merge incorporates history changes from other fish sessions | ||
3 | # it errors out if called in private mode | ||
4 | if test -z "$fish_private_mode" | ||
5 | builtin history merge | ||
6 | end | ||
7 | |||
8 | if not set --query fzf_history_time_format | ||
9 | # Reference https://devhints.io/strftime to understand strftime format symbols | ||
10 | set -f fzf_history_time_format "%m-%d %H:%M:%S" | ||
11 | end | ||
12 | |||
13 | # Delinate time from command in history entries using the vertical box drawing char (U+2502). | ||
14 | # Then, to get raw command from history entries, delete everything up to it. The ? on regex is | ||
15 | # necessary to make regex non-greedy so it won't match into commands containing the char. | ||
16 | set -f time_prefix_regex '^.*? │ ' | ||
17 | # Delinate commands throughout pipeline using null rather than newlines because commands can be multi-line | ||
18 | set -f commands_selected ( | ||
19 | builtin history --null --show-time="$fzf_history_time_format │ " | | ||
20 | _fzf_wrapper --read0 \ | ||
21 | --print0 \ | ||
22 | --multi \ | ||
23 | --scheme=history \ | ||
24 | --prompt="History> " \ | ||
25 | --query=(commandline) \ | ||
26 | --preview="string replace --regex '$time_prefix_regex' '' -- {} | fish_indent --ansi" \ | ||
27 | --preview-window="bottom:3:wrap" \ | ||
28 | $fzf_history_opts | | ||
29 | string split0 | | ||
30 | # remove timestamps from commands selected | ||
31 | string replace --regex $time_prefix_regex '' | ||
32 | ) | ||
33 | |||
34 | if test $status -eq 0 | ||
35 | commandline --replace -- $commands_selected | ||
36 | end | ||
37 | |||
38 | commandline --function repaint | ||
39 | end | ||