Add clojure completions#9272
Conversation
| (aliases)))' | ||
|
|
||
| function __fish_clj_aliases | ||
| which bb >/dev/null 2>&1; or return 1 |
There was a problem hiding this comment.
This should be command -q bb.
which is a cheesy external tool that might not be installed and might not give the right answer.
| end | ||
|
|
||
| function __fish_clj_tools | ||
| which bb >/dev/null 2>&1; or return 1 |
| @@ -0,0 +1,79 @@ | |||
| set bb_helper ' | |||
There was a problem hiding this comment.
This variable should be scoped - this will leak a $bb_helper variable into the user's environment.
I would probably either make it a function:
function __fish_bb_helper
echo '(require ...
# ...
)))'
endor make the "aliases" and "tools" function one and pass the argument "tools" from the completions calling it.
Or you could make it a local variable and have the other functions inherit it:
set -l bb_helper '...'
function __fish_clj_aliases -V bb_helperThis will copy the variable value at definition time into the function.
| complete -c clj -f -s r -l repl -d "Run a repl" | ||
| complete -c clj -r -d "Run a script from a file or resource" | ||
|
|
||
| complete -c clojure --wraps clj |
There was a problem hiding this comment.
This won't be loaded at the right time.
Fish finds completion files by command name, so if you try to complete "clojure" it will look for "clojure.fish".
That means once you have tried completing "clj" in the current session, the wrapper will be set up. But if you start a new shell and try to complete "clojure" before "clj" it won't work.
You'll have to add a file called "clojure.fish" that includes just this single line.
However: That's only if "clojure" is a common name set by upstream - if it's typically installed as both "clojure" and "clj".
If users usually set this up themselves, e.g. by using alias clojure=clj, then please just drop this. (alias would set up the wrapping)
There was a problem hiding this comment.
Both are typically installed and are widely used. clj is just clojure with a rlwrap wrapper for use in the repl. I'll make a separate clojure.fish file.
Thank you for the pointers. I'll fix the issues you've mentioned.
Clojure's command line is a bit odd. For the execution options -A, -M, -X and -T, it will take a colon separated list of aliases without any spaces between the option and the list (like clj -Mdev:debug:build). __fish_complete_list handles this nicely, but it would be nice if the description changed when making list suggestions, so that it first shows
❯ clj -<tab>
-A (Use concatenated aliases to modify classpath)
...
but once the user has typed -A and hits tab it would show something like
❯ clj -Ab<tab>
-Abuild (Alias)
-Abenchmark (Alias)
...
I was not able to figure out how to do this. Is it possible?
There was a problem hiding this comment.
If the completions for clj and clojure are identical or close to it, you can always put them in a function that takes the command name as a parameter, and invoke that from both clj.fish and clojure.fish. There are other workarounds such as defining clj as function clj --wraps clojure; command clj $argv; end; but that's the kind of thing you would do on your pc and not as part of the base fish installation.
| (aliases)))' | ||
|
|
||
| function __fish_clj_aliases -V bb_helper | ||
| command -q bb |
There was a problem hiding this comment.
You still need to ; or return here
|
Merged, thanks! |
|
Great! thanks |
Description
Completions for the Clojure cli tool. Both
cljandclojureis recognized. Will complete aliases and tools if babahka is installed.TODOs: