argcomplete icon indicating copy to clipboard operation
argcomplete copied to clipboard

fish-shell: function name is broken for local files (./script.py)

Open MaZderMind opened this issue 3 years ago • 4 comments

When Using argcomplete under Fish-Shell, the generated Code contains the literal Path to the Script as part of a function-name:

~/C/makefile-style-python register-python-argcomplete --shell fish ./foo/bar/baz

function __fish_./foo/bar/baz_complete
    set -x _ARGCOMPLETE 1
    set -x _ARGCOMPLETE_DFS \t
    set -x _ARGCOMPLETE_IFS \n
    set -x _ARGCOMPLETE_SUPPRESS_SPACE 1
    set -x _ARGCOMPLETE_SHELL fish
    set -x COMP_LINE (commandline -p)
    set -x COMP_POINT (string length (commandline -cp))
    set -x COMP_TYPE
    if set -q _ARC_DEBUG
        ./foo/bar/baz 8>&1 9>&2 1>/dev/null 2>&1
    else
        ./foo/bar/baz 8>&1 9>&2 1>&9 2>&1
    end
end
complete -c ./foo/bar/baz -f -a '(__fish_./foo/bar/baz_complete)'

__fish_./foo/bar/baz_complete is not a valid function name in Fish and thus | sourceing the generated Snippet results in an Error:

~/C/makefile-style-python register-python-argcomplete --shell fish ./foo/bar/baz | source
- (line 2): function: Illegal function name '__fish_./foo/bar/baz_complete'
function __fish_./foo/bar/baz_complete
^
from sourcing file -

Removing the offending Characters only leaving [a-zA-Z0-9] or a similar restrictive character-set would result in a workable Fish script.

MaZderMind avatar Oct 29 '20 22:10 MaZderMind

Does completion works after function name fix?

For me (fish 3.1.2) it doesn't. After changing complete -c ./foo/bar/baz -f -a '(__fish_foo_bar_baz_complete)' to complete -c baz -f -a '(__fish_foo_bar_baz_complete)' completion starts working as expected.

Can't find examples of fish complete with local files.

volkov avatar Nov 28 '20 06:11 volkov

After changing complete -c ./foo/bar/baz -f -a '(__fish_foo_bar_baz_complete)' to complete -c baz -f -a '(__fish_foo_bar_baz_complete)' completion starts working as expected.

https://github.com/fish-shell/fish-shell/issues/6001, fixed in fish 3.3.0.

faho avatar Jul 14 '21 10:07 faho

fixed in fish 3.3.0.

Nice!

Relative paths should be also supported in generated script body - running completion from different directory would fail now.

Probably it's better to use single completion function for fish, like for bash. Disabling completions descriptions should be also changed with this approach because it's done by modifying script.

volkov avatar Aug 02 '21 04:08 volkov

After fish-shell/fish-shell#6001 completion registered via complete -p /home/auser/myscript ... work for /home/user/myscript and ./myscript but not for ~/myscript.

@faho is this expected or it should be reported?

There is workaround: if I register command via complete -c myscript ... all three cases works, but also completion is invoked for any other script with same name.

UPD: reported as fish-shell/fish-shell#8442

volkov avatar Nov 07 '21 12:11 volkov