-
Notifications
You must be signed in to change notification settings - Fork 476
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
allow bash completion to complete tasks in other directories #1303
Conversation
c2979e7
to
637ead1
Compare
@casey Can you take a look at this one again? I believe I addressed all your previous points. |
Sorry for the delay! Just checked it out, and I think there's a bug. One the left is the result of me typing |
@casey That's very odd. A bash completion only writes to the Here are some tests I did from this branch: $ source ./completions/just.bash
$ COMP_WORDS=(just) && COMP_CWORD=1 _just just && declare -p COMPREPLY
declare -a COMPREPLY=([0]="build" [1]="build-book" [2]="changes" [3]="check" [4]="ci" [5]="clippy" [6]="done" [7]="filter" [8]="fmt" [9]="forbid" [10]="fuzz" [11]="generate-completions" [12]="install" [13]="install-dev-deps" [14]="install-dev-deps-homebrew" [15]="man" [16]="polyglot" [17]="pr" [18]="publish" [19]="push" [20]="pwd" [21]="quine" [22]="render-readme" [23]="replace" [24]="run" [25]="sloc" [26]="test" [27]="test-quine" [28]="view-man" [29]="watch" [30]="watch-readme")
$ COMP_WORDS=(just i) && COMP_CWORD=1 _just just && declare -p COMPREPLY
declare -a COMPREPLY=([0]="install" [1]="install-dev-deps" [2]="install-dev-deps-homebrew")
$ COMP_WORDS=(just r) && COMP_CWORD=1 _just just && declare -p COMPREPLY
declare -a COMPREPLY=([0]="render-readme" [1]="replace" [2]="run") And now with just 1.4.0: $ eval "$(just --completions bash)"
$ COMP_WORDS=(just) && COMP_CWORD=1 _just just && declare -p COMPREPLY
declare -a COMPREPLY=([0]="build" [1]="build-book" [2]="changes" [3]="check" [4]="ci" [5]="clippy" [6]="done" [7]="filter" [8]="fmt" [9]="forbid" [10]="fuzz" [11]="generate-completions" [12]="install" [13]="install-dev-deps" [14]="install-dev-deps-homebrew" [15]="man" [16]="polyglot" [17]="pr" [18]="publish" [19]="push" [20]="pwd" [21]="quine" [22]="render-readme" [23]="replace" [24]="run" [25]="sloc" [26]="test" [27]="test-quine" [28]="view-man" [29]="watch" [30]="watch-readme")
$ COMP_WORDS=(just i) && COMP_CWORD=1 _just just && declare -p COMPREPLY
declare -a COMPREPLY=([0]="install" [1]="install-dev-deps" [2]="install-dev-deps-homebrew")
$ COMP_WORDS=(just r) && COMP_CWORD=1 _just just && declare -p COMPREPLY
declare -a COMPREPLY=([0]="render-readme" [1]="replace" [2]="run") The version of bash I'm using is |
I found a different bug, and fixed it.
It would be great to add those as unit tests somehow. |
If you could add unit tests for this, that would be amazing. So far I haven't because I'm not sure how to do that 😅 |
Sorry if this is a tangent, but I noticed that the completion script won't complete filenames in some contexts: for example, after |
I've used BATS (https://bats-core.readthedocs.io/) in the past. It's focused on bash, instead of zsh or plain sh, but it may be flexible enough to allow tests for other shells, too. It has been in active development for many years. A recent alternative is https://shellspec.info, but I'm not too familiar with it. Its "BDD" API seems pretty weird to me. One alternative is to write our own test script for now. |
@casey I added a custom script to test completion of bash. That could be extended later for other shells. And could be converted to BATS, if needed. |
for future reference, I found out abotu that way to test bash completion here: https://stackoverflow.com/questions/3520936/accessing-bash-completions-for-specific-commands-programmatically |
Sorry for the delay once again! Taking a look again, and the tests seem to still be failing locally for me:
Also, the tests should run against a test justfile, since otherwise the tests will need to be updated every time the main justfile changes. |
23d9a55
to
293394b
Compare
@casey interesting... My guess is that this is caused by a different bash version. Which I'm on Naturally, I'll try to adapt them to pass regardless. |
Ah, good point. I have the super old |
@casey This should be good to be merged then. The change works (for me , at least), and tests are passing. I think that code should even work on the older bash you had before. The issue was only on the test diff. |
293394b
to
0abd675
Compare
@casey can you take a look at this again? I think it's ready to be merged, unless you have some pending concerns I missed. |
Sorry for letting this sit for so long! Looks good, although can you make it use a dummy justfile that's only used for the test, instead of the project's justfile? If it uses the main justfile, then it will break when it changes. |
sounds reasonable. I'll make the change. |
Co-authored-by: Casey Rodarmor <casey@rodarmor.com>
0abd675
to
a9933c7
Compare
@casey updated. Tests don't rely on the main justfile anymore. |
Nice! Overall looks good. Instead of creating a tempdir and temp justfile, how about committing the test justfile to |
deb88fb
to
24d9afa
Compare
@casey done. I created and commited two test justfiles, and used those. :) |
24d9afa
to
40fe20c
Compare
Nice, merged! Thanks for sticking with this! |
Today, I learned about just's ability to invoke justfiles in other directories.
I moved part of my tasks into
./ci/justfile
. Then, with bash completion on, typedjust ci/
+ tab. It completed with files, not withjust
tasks.This change here solves that problem.
If the current text being completed has a
/
char, we'll run a differentjust --summary
command.