-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add clojure completions #9272
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
Add clojure completions #9272
Conversation
share/completions/clj.fish
Outdated
(aliases)))' | ||
|
||
function __fish_clj_aliases | ||
which bb >/dev/null 2>&1; or return 1 |
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.
This should be command -q bb
.
which
is a cheesy external tool that might not be installed and might not give the right answer.
share/completions/clj.fish
Outdated
end | ||
|
||
function __fish_clj_tools | ||
which bb >/dev/null 2>&1; or return 1 |
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.
(same as above)
share/completions/clj.fish
Outdated
@@ -0,0 +1,79 @@ | |||
set bb_helper ' |
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.
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 ...
# ...
)))'
end
or 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_helper
This will copy the variable value at definition time into the function.
share/completions/clj.fish
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
share/completions/clj.fish
Outdated
(aliases)))' | ||
|
||
function __fish_clj_aliases -V bb_helper | ||
command -q bb |
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.
You still need to ; or return
here
Merged, thanks! |
Great! thanks |
Description
Completions for the Clojure cli tool. Both
clj
andclojure
is recognized. Will complete aliases and tools if babahka is installed.TODOs: