Skip to content

feat(completion): let fish complete global tasks if -g or --global is passed #2134

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

atusy
Copy link
Contributor

@atusy atusy commented Mar 21, 2025

In the current implementation, fish completion suggests local tasks regardless of -g or --global options.
This PR fixes the problem by adding a feature to detect these options and then suggesting global tasks if likely.

I hope this PR can be merged although I do not implement the feature for bash and zsh.
I am not familiar with them...

@atusy

This comment was marked as resolved.

@atusy atusy closed this Mar 21, 2025
# Check if the global task is requested
set -l global_task false
set -l cmd_args
eval "set cmd_args $(commandline -b)" # split arguments by spaces while taking into account of quotes and escapes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

eval is dangerous.

Let's say commandline is

$ foo --global; task

then eval evaluates

set cmd_args foo --global; task

which in turn

  1. evaluates task default...
  2. shows global tasks althoug -g and --global are not specified to task

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I found the problem can be fixed by selecting only a part of commandline instead of whole.

5f53cf0

If this is still unlikely, I would avoid eval and instead simply split arguments by spaces.

set -l cmd_args "$commandline --current-process | string split ' '"

The caveat is that string split will complete global tasks in some unexpected cases (e.g., task "foo -g").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I find a way to avoid eval!
read --tokenize is what we need.

…rsor

before the fix, `eval` occasionally runs extra commands.

```
$ foo --global; task
```

then `eval` evaluates

```
set cmd_args foo --global; task
```

which in turn

1. evaluates `task default`...
2. shows global tasks althoug `-g` and `--global` are not specified to `task`
@atusy atusy reopened this Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant