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

Filter tasks with in bash tab-complete sample #46

Merged
merged 2 commits into from Mar 23, 2022

Conversation

slimslenderslacks
Copy link
Contributor

The .bashrc example could tab-complete task names if we filter
tasks using the current arg.

The .bashrc example could tab-complete long task names if we filter out
tasks using the current arg.
src/tasks.adoc Outdated
@@ -266,7 +266,7 @@ Add this to your `.bashrc` to get tab-complete feature on bash.
[source,bash]
----
_bb_tasks() {
COMPREPLY+=(`bb tasks |tail -n +3 |cut -f1 -d ' '`)
COMPREPLY=( $(compgen -W "$(bb-util tasks |tail -n +3 |cut -f1 -d ' ')" -- ${COMP_WORDS[COMP_CWORD]}) );
Copy link
Contributor

Choose a reason for hiding this comment

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

what is bb-util?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bb-util is a wrapper script (for running bb.edns in other directories). Sorry about that.

@borkdude
Copy link
Contributor

My bash is not so good. Can you explain in lay man terms what this change means and how the behavior changes?

@slimslenderslacks
Copy link
Contributor Author

slimslenderslacks commented Jan 20, 2022

In the new version, if you have 3 tasks (atask1, atask2, and btask1), and you type bb <tab>, you'll still see

12:56 $ bb
atask1       atask2    btask1

but then if you type bb a<tab>, you'll see the options reduced to two

12:56 $ bb a
atask1       atask2

and if you type bb b<tab> it should just auto-complete the whole btask1

So that compgen command is filtering the list of task names based on the current partially typed argument.

@slimslenderslacks
Copy link
Contributor Author

I think ${COMP_WORDS[COMP_CWORD]} will always give you the last, potentially partially typed, argument on the command line.

@slimslenderslacks
Copy link
Contributor Author

slimslenderslacks commented Jan 20, 2022

In a sense, I guess this is letting bash filter the set of tasks based on what you've partially typed and if you've typed enough to just auto-complete the word, then it completes the typing for you.
Not sure whether the other non-bash examples do the already.

@borkdude
Copy link
Contributor

Neat! I'll try it locally.

@slimslenderslacks
Copy link
Contributor Author

Another option could be to pass ${COMP_WORDS[COMP_CWORD]} to bb tasks to let bb filter the tasks. If the tasks were to one day support parameter metadata, you could auto-complete --param-names and even run param-values validators using I guess.

@borkdude borkdude merged commit 1cae242 into babashka:master Mar 23, 2022
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.

None yet

3 participants