-
-
Notifications
You must be signed in to change notification settings - Fork 669
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
base: main
Are you sure you want to change the base?
Conversation
Otherwise, `set` may modify a global variable with the same name.
This comment was marked as resolved.
This comment was marked as resolved.
completion/fish/task.fish
Outdated
# 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 |
There was a problem hiding this comment.
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
- evaluates
task default
... - shows global tasks althoug
-g
and--global
are not specified totask
There was a problem hiding this comment.
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.
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"
).
There was a problem hiding this comment.
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`
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...