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

Escape and complete -C (for fzf completion widget) #3469

Closed
Ambrevar opened this issue Oct 17, 2016 · 5 comments · Fixed by #8645
Closed

Escape and complete -C (for fzf completion widget) #3469

Ambrevar opened this issue Oct 17, 2016 · 5 comments · Fixed by #8645
Labels
bug Something that's not working as intended
Milestone

Comments

@Ambrevar
Copy link
Contributor

Ambrevar commented Oct 17, 2016

fish 2.3.1, Arch Linux, urxvt 9.22

I am trying to write a widget to replace fish completion menu with fzf. (Awesome, right? ;) )

The idea is simple:

## Boilerplate...
complete -C | fzf... | read result
## Some code to replace the token with $result.

Problem is, complete -C unescapes the tokens a bit too much, which makes variables indistinguishable from escaped dollars.

Example:

set HFOO 42
echo \$HOME-$H<binding>

Replace <binding> with a binding to a function that prints out complete -C. Result:

$HOME-$HOME
$HOME-$HFOO

The result is unusable since there is no way for the calling function to know what should be escaped.

The normal completion does preserve the escaped token though:

\$HOME-$HOME
\$HOME-$HFOO

I think complete -C should do the same.

This might be related to #1127.

@faho faho added the bug Something that's not working as intended label Oct 19, 2016
@faho faho added this to the fish-future milestone Oct 19, 2016
@faho
Copy link
Member

faho commented Oct 19, 2016

Yes, can reproduce.

We have a bunch of issues with escaping (because it's really confusing), but I can't find this particular one.

@ViViDboarder
Copy link

I've been working on something like this with fzf for certain completions.

I put together the following function to use, but I see issues as well.

Not every time, but sometimes it will clear the entire command line (including prompt) from the view. Other times it will call fzf multiple times and try to do multiple completions. So far I haven't figured the issues or why they are only sporadic.

Interested to see if you've had any more luck!

@Ambrevar
Copy link
Contributor Author

Ambrevar commented Feb 2, 2018

Correct me if I'm wrong, but I think you are referring to a different issue, namely process management and/or file descriptor management. fish has had several issues in that area in the past. You might want to keep looking in the issue tracker.

The issue from the original post related to the badly escaped output of the complete -C command.

krobelus added a commit to krobelus/fish-shell that referenced this issue Oct 3, 2019
@krobelus
Copy link
Member

krobelus commented Oct 3, 2019

For complete -C'\$HOME-$H', I can imagine two possible behaviors:

  1. \$HOME-/home/johndoe

That is, expand the completed token. This may be worthwile, assuming that completions are short-lived.

  1. \$HOME-$HOME

I have an implementation of this one at escape-complete-C.
This would break third party scripts using complete -C (mostly used for completing subcommands I guess).

@nzig
Copy link
Contributor

nzig commented Jan 15, 2022

@krobelus Could this be fixed by taking the implementation in your branch, but gating it behind a --unescaped flag as suggested in #4570 (comment) and discussed in #8441? This would avoid the problem of breaking scripts using complete -C, but allow the use case in this issue.

I will open a PR for this.

nzig added a commit to nzig/fish-shell that referenced this issue Feb 7, 2022
krobelus pushed a commit to nzig/fish-shell that referenced this issue Feb 9, 2022
An example use case is an external completion pager:

    bind \cg "commandline -rt (complete -C --escape|fzf|cut -d\t -f1)\ "

Fixes fish-shell#3469
krobelus pushed a commit that referenced this issue Feb 9, 2022
An example use case is an external completion pager:

    bind \cg "commandline -rt (complete -C --escape|fzf|cut -d\t -f1)\ "

Fixes #3469
@zanchey zanchey modified the milestones: fish-future, fish 3.4.0 Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that's not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants