Skip to content

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
@andreynering
Copy link
Member

Thank you @atusy!

@andreynering andreynering merged commit 7416b7d into go-task:main Apr 19, 2025
14 checks passed
andreynering added a commit that referenced this pull request Apr 19, 2025
@atusy
Copy link
Contributor Author

atusy commented Apr 19, 2025

My pleasure!!

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.

2 participants