fzf icon indicating copy to clipboard operation
fzf copied to clipboard

History mistakenly separates on \n\t

Open jagprog5 opened this issue 2 years ago • 2 comments

  • [x] I have read through the manual page (man fzf)
  • [x] I have the latest version of fzf
  • [x] I have searched through the existing issues

Info

  • OS
    • [x] Linux
    • [ ] Mac OS X
    • [ ] Windows
    • [ ] Etc.
  • Shell
    • [x] bash
    • [ ] zsh
    • [ ] fish

Problem / Steps to reproduce

history -s $'first_line\n\tsecond_line'

On ctrl-r, the history is displayed as two different command despite being a single entry:

>   1500    second_line
    1501    first_line

The code that does this separation is here.

I would expect the single history entry to be displayed on one line in the interface.

jagprog5 avatar Feb 17 '23 17:02 jagprog5

I've tried to reproduce the problem with

echo "foo
	bar"

and

echo "bar
	baz"

and it looks like bash itself is unable to handle these entries properly.

Excerpt from the output of HISTTIMEFORMAT= history:

159862  echo "foo
159863          bar"
159864  echo "bar
159865          baz"

Same from fc -l

159862   echo "foo
159863          bar"
159864   echo "bar
159865          baz"

And !159865 gives

$ !159865
        bar"
>

So I'm not sure if there's anything we can do about it.

junegunn avatar Feb 18 '23 11:02 junegunn

Related solution regarding how to stop a multiline entry from splitting into multiple entries, if you're willing to enforce a HISTTIMEFORMAT. Although this is kicking the can down the road since it's just changing the separator to something less ubiquitous. I wonder if it can include a null char.

Also I'm confused by the output you listed since it should only do this after exiting the shell and entering back in, at that point it loads the histfile data, which is where it is stored ambiguously. But before then, it's ok.

$ history -s $'first_line\n\tsecond_line'
$ history | tail
  843  clear
  844  ls
  845  line1
  846   line2
  847  history
  848  exit
  849  history
  850  first_line
        second_line
  851  history | tail

jagprog5 avatar Feb 18 '23 17:02 jagprog5