fish-shell / fish-shell

The user-friendly command line shell.

Home Page:https://fishshell.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`commandline` command breaks quoting

maxfl opened this issue · comments

I've found this issue after updating to the master after new version announcement. Just updated to to the latest master and the issue is still there.

To repeat use the following command:

bind -m insert -M insert  \ea 'commandline -b; commandline -f repaint;'
bind \ea 'commandline -b; commandline -f repaint;'

Then press Up and AltA. The printed command will lack quotes. Something wrong happened to '\ea' as well. I'm not sure concerning '\ea' but quoting was working around month before, I use this feature to edit commandline in the editor.

It seems that issue exists in v2.2.0 as well

When I press Up and Alt-A, another line showed up, do you mean that?

This command is supposed to print the current command line contents. It is easier to test it when it's binded to a key.

When you press up it selects the command that was used to bind. This command contains special character \e and quotes. As you press AltA it should print the command line contents. The line printed contains no quotes and no special characters which I find to be a bug, because I suppose that fish should be able to parse the code that is output from the commandline command (commandline -b | source).

If you are confused by output, which looks not that pretty, you can use the following test:

bind -m insert -M insert \ea 'commandline -b >commandline_test.out'
bind \ea 'commandline -b >commandline_test.out'

As you press Up AltA, the contents of a command line should be printed to the file commandline_test.out. Still there are no quotes and no special characters.

Summary

Reproduce it with:

bind -m insert -M insert \ea 'commandline -b >commandline_test.out'
bind \ea 'commandline -b >commandline_test.out'

And press Up and Alt-A.
Problem: No quotes and special characters are saved into commandline_test.out.
Solution: I don't know. Maybe related to builtin_commandline.cpp.

This is a regression from 2.1.1.

Just ran into that issue as well on fish-shell 2.2.0. See my comment at #150.

Still experiencing this using the fish nightlies - quite frustrating. Adding my own use case into the mix:

Setup

$ cat ~/.config/fish/functions/fish_user_key_bindings.fish

function comment_line
  set -l cmd (commandline)
  commandline \#$cmd
  commandline -f repaint
end

bind \e# comment_line

Example

$ echo "foo bar"
<alt+# pressed>
$ #echo foo bar

Looks like this was introduced in 2008415, which was intended to fix #2075. I don't know why an unescape was added to the non-tokenized codepath. Seems like a mistake.