Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zsh] Fix backslash escaping #3909

Merged
merged 1 commit into from
Jul 4, 2024
Merged

[zsh] Fix backslash escaping #3909

merged 1 commit into from
Jul 4, 2024

Conversation

junegunn
Copy link
Owner

@junegunn junegunn commented Jul 4, 2024

Fix #3859

To test:

FZF_CTRL_T_COMMAND="echo -E 'foo\bar\baz'; echo -E 'hello\world'"

_fzf_compgen_path() {
  eval $FZF_CTRL_T_COMMAND
}

source shell/key-bindings.zsh
source shell/completion.zsh

Fix #3859

To test:

  FZF_CTRL_T_COMMAND="echo -E 'foo\bar\baz'; echo -E 'hello\world'"

  _fzf_compgen_path() {
    eval $FZF_CTRL_T_COMMAND
  }

  source shell/key-bindings.zsh
  source shell/completion.zsh
@LangLangBart
Copy link
Contributor

I guess you have already found the desired formula.


print -nr -- … should have worked as well.

--- a/shell/key-bindings.zsh
+++ b/shell/key-bindings.zsh
@@ -53,6 +53,6 @@ __fzf_select() {
   FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} \
   FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \
-  FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" < /dev/tty | while read item; do
-    echo -n "${(q)item} "
+  FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" < /dev/tty | while read -r item; do
+    print -nr -- "${(q)item} "
   done
   local ret=$?

or bsd_echo

--- a/shell/key-bindings.zsh
+++ b/shell/key-bindings.zsh
@@ -49,9 +49,9 @@ __fzf_defaults() {
 # CTRL-T - Paste the selected file path(s) into the command line
 __fzf_select() {
-  setopt localoptions pipefail no_aliases 2> /dev/null
+  setopt localoptions pipefail no_aliases bsd_echo 2> /dev/null
   local item
   FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} \
   FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \
-  FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" < /dev/tty | while read item; do
+  FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" < /dev/tty | while read -r item; do
     echo -n "${(q)item} "
   done

@junegunn
Copy link
Owner Author

junegunn commented Jul 4, 2024

Thanks. Do they have pros and cons or are they more or less the same and it doesn't matter which one we choose?

@LangLangBart
Copy link
Contributor

Thanks. Do they have pros and cons or are they more or less the same and it doesn't matter which one we choose?

Difference between echo and print.

3.2.1: Builtins for printing
The commands echo' and print' are shell builtins; they just show what you typed, after the shell has removed all the quoting. The difference between the two is really historical: echo' came first, and only handled a few simple options; ksh provided print', which had more complex options and so became a different command. The difference remains between the two commands in zsh; if you want wacky effects, you should look to print. Note that there is usually also an external command called echo, which may not be identical to zsh's; there is no standard external command called print, but if someone has installed one on your system, the chances are it sends something to the printer, not the screen.

Source: A User's Guide to the Z-Shell

print comes with more flags, making it useful for special cases, but using echo -nE or print -nr -- is indifferent here.

@junegunn junegunn merged commit 23a391e into master Jul 4, 2024
5 checks passed
@junegunn junegunn deleted the fix-zsh-backslash-escaping branch July 4, 2024 16:46
junegunn added a commit that referenced this pull request Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing directory slashes when completion chosen
2 participants