Skip to content

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

Closed

Description

@Ambrevar

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.

Activity

  1. added
    bug
    on Oct 19, 2016
  2. added this to the fish-future milestone on Oct 19, 2016
  3. faho commented on Oct 19, 2016

    @faho
    Member

    Yes, can reproduce.

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

  4. ViViDboarder commented on Feb 2, 2018

    @ViViDboarder

    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!

  5. Ambrevar commented on Feb 2, 2018

    @Ambrevar
    ContributorAuthor

    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.

  6. added a commit that references this issue on Oct 3, 2019
    38b4fe5
  7. krobelus commented on Oct 3, 2019

    @krobelus
    Contributor

    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).

  8. added a commit that references this issue on Jan 15, 2022
    7aa6134
  9. nzig commented on Jan 15, 2022

    @nzig
    Contributor

    @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.

  10. added a commit that references this issue on Feb 7, 2022
    fa6f690
  11. added a commit that references this issue on Feb 9, 2022
    7ff32af
  12. added a commit that references this issue on Feb 9, 2022
    9e0f74e
  13. locked as resolved and limited conversation to collaborators on Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions