Task: Add Bash, ZSH and Windows command line completion

Created on 11 Mar 2018  路  14Comments  路  Source: go-task/task

Add bash and zsh autocomplete feature.

feature help wanted

Most helpful comment

I've made some work on bash autocompletion here: https://github.com/bfarayev/task/blob/feature/autocomplete/completion/task.bash

I've tested it on my fork of task, so need to check if it'd work with the latest release. Happy to submit a PR after testing.

All 14 comments

@harobed I'd love to receive contributions in this one, since I don't actually know how that works. Let me know if you want to work in it.

Edited title to include Windows as asked on #127

I am very interested in this feature. I have a very simple and not very complete command I use for bash:

# Taskfile.yml autocomplete - ASSUMES ALL TASKS ARE LOWERCASE
complete -W "\`test -e Taskfile.yml && grep -oE '^\s\s[a-z0-9_-]+:([^=]|$)' Taskfile.yml | sed 's/[^a-zA-Z0-9_-]*$//'\`" task

This does not work with:

  • included files
  • uppercase tasks, I went with lowercase otherwise it would return some of the variables I have defined

This also seems like a nice resource: https://iridakos.com/tutorials/2018/03/01/bash-programmable-completion-tutorial.html

I thing I have linked this previously, but another resource is:

I've made some work on bash autocompletion here: https://github.com/bfarayev/task/blob/feature/autocomplete/completion/task.bash

I've tested it on my fork of task, so need to check if it'd work with the latest release. Happy to submit a PR after testing.

@bfarayev Pull requests are more than welcome!

Can this be implemented as new Task command?
Example:
task generate-completion --bash >> ~/.bashrc

Can this be implemented as new Task command?
Example:
task generate-completion --bash >> ~/.bashrc

Does other tools usually do that?

Drush 8 used to have init command that installed completion file.
https://github.com/drush-ops/drush/blob/8.3.2/commands/core/init.drush.inc#L83

Also https://github.com/bamarni/symfony-console-autocomplete is widely used tool for generating completions for Symfony Console commands.

Typically such approach is used in applications that distributed as a single file executable. If an application has installation/uninstallation procedure it's probably better to install/uninstall the completions automatically.

@Chi-teck Sounds like a good idea. Can you create a separate issue for that?

@andreynering what is the scope of this ticket then?

@Chi-teck This issue is about creating the completion scripts alone.

I propose one to implement the auto-install command you mentioned. As a comment, it'd be more likely forgotten with time.

@sawadashota I opened a PR to improve the installation of autocompletions here:

https://github.com/sawadashota/go-task-completions/pull/2

One thing I noticed is that task -l only prints targets with descriptions. I think it should print all targets, regardless of description.

Was this page helpful?
0 / 5 - 0 ratings