Skip to content

Commit

Permalink
Fix multi-line command bug
Browse files Browse the repository at this point in the history
Before, selecting a multi-line command when using the search command history feature would result in the command lined being replaced with only the top line of the selected command.
For example, selecting this command from history...
  function example
      echo "This is just an example"
  end
...would result in the command line becoming...
  function example
with the rest of the command lost.

The bug occurred because when a command substitution has a multi-line output and is assigned to a variable, each line of the output is give its own index in the variable. So, referencing index 2 only gave us one line of the command. To fix this, we have to string collect the multi-line output into a single string before assigning it.
This fixes the bug by doing just that so users can now select the entirety of multi-line commands from history.
  • Loading branch information
PatrickF1 committed Jan 13, 2021
1 parent d89cd0c commit 8bacfb3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion functions/__fzf_search_history.fish
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ function __fzf_search_history --description "Search command history. Replace the
set command_with_ts (
# Reference https://devhints.io/strftime to understand strftime format symbols
builtin history --null --show-time="%m-%d %H:%M:%S | " |
fzf --read0 --tiebreak=index --query=(commandline)
fzf --read0 --tiebreak=index --query=(commandline) |
string collect
)

if test $status -eq 0
Expand Down

0 comments on commit 8bacfb3

Please sign in to comment.