Skip to content

Fish complete snippet in cookbook breaks when completing file paths #1881

@youwen5

Description

@youwen5
| update value { str replace "\"" "\\\"" | $"($in)" }

This seems to not work properly. If you try to tab complete and fish returns file paths, it'll insert one double quote into the line and fish --complete will error out. You have to manually fix the quote. For example, if I'm trying to open a PDF with zathura, and I type

zathura (there is a space here)

and hit tab, it'll insert a quote

zathura "

and then fish --complete will complain about the unpaired quote. If you manually add the quote

zathura ""

Then completion works as expected. Or if you already begin typing a file path

zathura ~/Documents

It will work too. Only when you type a command, a space right after, and then hit tab, it'll insert the single unpaired quote and break.

This snippet that I got from a comment in this issue has worked much better for me so far.

let fish_completer = {|spans|
    fish --command $'complete --escape "--do-complete=($spans | str join " ")"'
    | $"value(char tab)description(char newline)" + $in
    | from tsv --flexible --no-infer
    | each {|i|
        if '\' in $i.value {
            $i | merge {'value': $"\"($i.value | str replace -a '\' '')\""}
        } else {$i}
    }
}

Originally posted by @youwen5 in #1844 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions