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

completion ignoring . prefixed arguments #3707

Closed
1 of 2 tasks
nhooyr opened this issue Jan 6, 2017 · 10 comments
Closed
1 of 2 tasks

completion ignoring . prefixed arguments #3707

nhooyr opened this issue Jan 6, 2017 · 10 comments
Assignees
Milestone

Comments

@nhooyr
Copy link
Contributor

nhooyr commented Jan 6, 2017

  • Have you checked if problem occurs with fish 2.4.0?
  • Tried fish without third-party customizations (check sh -c 'env HOME=$(mktemp -d) fish')?

fish version installed (fish --version): 2.4.0

OS/terminal used: macOS 10.12.2 iTerm 3.0.13

completion ignores arguments that start with .. I think this is to ignore dotfiles but I have a command that can be completed with a file that starts with . and it should not be ignored. Is it possible to disable this?

watch https://asciinema.org/a/9wnu3jy22hxfjf4au18m7ob29

@ridiculousfish ridiculousfish added the bug Something that's not working as intended label Jan 8, 2017
@ridiculousfish ridiculousfish added this to the fish-future milestone Jan 8, 2017
@ridiculousfish
Copy link
Member

This is by design. The default file completion will only show hidden files if your argument starts with a . After all, hidden files should be hidden.

We wouldn't introduce a config option for this.

I thought it should be possible to write a custom completion, but it looks like fish squashes custom completions that start with . unless the token starts with . (I thought this only happened for file completions, but it looks like it happens all the time). That's probably a bug, and one that can be fixed.

For now though I think this just isn't possible, sorry!

@nhooyr
Copy link
Contributor Author

nhooyr commented Jan 8, 2017

I'm asking about custom completion not for file completion.

@krader1961
Copy link
Contributor

@nhooyr: Please update this issue with your custom completion script that is not working as you desire. I cannot tell from your asciinema recording what complete commands were in effect that you expected to behave differently. Also, your asciinema recording is ambiguous since it has insufficient context, in conjunction with this issue, to understand what is not working as you expected.

It should be possible to inhibit the usual file name completion for strings beginning with .. But that is clearly an enhancement and we need more details about your use case.

@krader1961 krader1961 added enhancement and removed bug Something that's not working as intended labels Feb 11, 2017
@nhooyr
Copy link
Contributor Author

nhooyr commented Feb 11, 2017

Sorry, I didn't realize I was so unclear when I wrote this.

Here is the script https://github.com/nhooyr/dotfiles/blob/812056d8e13d99dd6bb3eced79b8d13dbb8e91d5/.config/fish/completions/bd.fish

Fish doesn't show me .config .foo .bar if I don't have a period in front when I attempt to complete. It only shows me foo 99j bar.

@krader1961
Copy link
Contributor

Hmmm, okay, you're adding an explicit completion that includes arguments that begin with a period:

complete -c bd -f -a '.config foo 99j .foo .bar bar'

And those do not show up in the completion list. I'm inclined to agree that explicitly enumerating arguments that begin with a period should be displayed and selectable after pressing [tab] even if you haven't typed a period. Whereas the behavior for file name expansion should continue to exclude such file names unless you have started the argument with a period before pressing [tab].

@ridiculousfish
Copy link
Member

Yes, me too - the hidden file behavior is only supposed to apply to files, not bespoke completions.

@rmartine-ias
Copy link

I would like this too

This would be a useful enhancement to me -- my company has a practice of having CI code in a .ci/ directory, and I frequently make changes to it. git add does not tab complete the files in that directory. It looks like it should:

complete -f -c git -n '__fish_git_using_command add' -a '(__fish_git_files modified untracked deleted unmerged modified-staged-deleted)'

(__fish_git_files correctly returns the dot-prefixed paths. I think it would make sense, like you said, for explicitly added completions to work, even if they start with a dot.)

Each time I do a tab completion for this, I get confused for a second, go "oh right", and add a dot and press tab again. It's a minor annoyance, but one I deal with very frequently.


Temp. solution for git add specifically

Now that I've figured out it's fish's fault, and not a misconfigured git, I can do something about it. For anyone else with this same exact git add issue, here's a solution (excuse my poor fish):

function confirm -a 'prompt' -d "Confirm whether or not to do something"
    if test -z "$prompt"
        set prompt 'Are you sure?'
    end

    read -f -p "set_color green; echo \"$prompt [y/N]\"; set_color normal" response
    switch "$response"
        case y Y
            true
        case '*'
            false
    end
end

function gap -d "Git add one file, or prompt for all"
    if [ (git status --porcelain | wc -l) = 1 ]
        git add -v -A # -v prints the added file
    else
        # can we prompt one by one, but better than git add --interactive?
       git status; confirm "Add all?"; and git add -A
    end
end

Replacing ga <tab><return> with gap<return> is.. better. Remember as "git add, please".

ridiculousfish added a commit to ridiculousfish/fish-shell that referenced this issue Sep 13, 2022
By default, fish does not complete files that have leading dots, unless the
wildcard itself has a leading dot. However this also affected completions;
for example `git add` would not offer `.gitlab-ci.yml` because it has a
leading dot.

Relax this for custom completions. Default file expansion still
suppresses leading dots, but now custom completions can create
leading-dot completions and they will be offered.

Fixes fish-shell#3707.
@ridiculousfish
Copy link
Member

Fixed in b7de768. Thank you for filing.

@bricker

This comment was marked as outdated.

zanchey pushed a commit that referenced this issue Dec 31, 2023
By default, fish does not complete files that have leading dots, unless the
wildcard itself has a leading dot. However this also affected completions;
for example `git add` would not offer `.gitlab-ci.yml` because it has a
leading dot.

Relax this for custom completions. Default file expansion still
suppresses leading dots, but now custom completions can create
leading-dot completions and they will be offered.

Fixes #3707.

(cherry picked from commit b7de768)
@zanchey zanchey modified the milestones: fish next-3.x, fish 3.7.0 Dec 31, 2023
@miyl

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants