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

Use stack's dynamic completions #9681

Merged
merged 2 commits into from Mar 27, 2023
Merged

Use stack's dynamic completions #9681

merged 2 commits into from Mar 27, 2023

Conversation

chrismwendt
Copy link
Contributor

Stack has support for on-the-fly completions, so let's use them.


complete -c stack -n '__fish_seen_subcommand_from exec' -a "(ls $project_path/.stack-work/install/**/bin/)"
stack --fish-completion-script (command -v stack) | source
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the output look like? Is it actually any good?

Also note that this is reachable with a function called stack, so passing the path is awkward because there might not be a command. Why is that needed anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the output:

 function _stack
    set -l cl (commandline --tokenize --current-process)
    # Hack around fish issue #3934
    set -l cn (commandline --tokenize --cut-at-cursor --current-process)
    set -l cn (count $cn)
    set -l tmpline --bash-completion-enriched --bash-completion-index $cn
    for arg in $cl
      set tmpline $tmpline --bash-completion-word $arg
    end
    for opt in (/Users/chrismwendt/.local/bin/stack $tmpline)
      if test -d $opt
        echo -E "$opt/"
      else
        echo -E "$opt"
      end
    end
end

complete --no-files --command stack --arguments '(_stack)'

Seems to work better than the static file (notice how it completes options, too, not just commands):

CleanShot 2023-03-23 at 02 04 32@2x

CleanShot 2023-03-23 at 02 07 24@2x

stack --fish-completion-script stack | source works just as well, committed in 0ff59a7.

@faho faho added this to the fish 3.6.2 milestone Mar 27, 2023
@faho faho merged commit 3a72d09 into fish-shell:master Mar 27, 2023
6 checks passed
@faho
Copy link
Member

faho commented Mar 27, 2023

Merged, thanks!

@chrismwendt chrismwendt deleted the patch-1 branch July 11, 2023 08:55
faho pushed a commit that referenced this pull request Sep 8, 2023
* Use dynamic completions for stack

* Pass the plain command

(cherry picked from commit 3a72d09)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants