Skip to content

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

Merged
merged 7 commits into from
Oct 14, 2022
Merged

Add clojure completions #9272

merged 7 commits into from
Oct 14, 2022

Conversation

kthu
Copy link
Contributor

@kthu kthu commented Oct 12, 2022

Description

Completions for the Clojure cli tool. Both clj and clojure is recognized. Will complete aliases and tools if babahka is installed.

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

(aliases)))'

function __fish_clj_aliases
which bb >/dev/null 2>&1; or return 1
Copy link
Member

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.

end

function __fish_clj_tools
which bb >/dev/null 2>&1; or return 1
Copy link
Member

Choose a reason for hiding this comment

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

(same as above)

@@ -0,0 +1,79 @@
set bb_helper '
Copy link
Member

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.

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
Copy link
Member

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)

Copy link
Contributor Author

@kthu kthu Oct 12, 2022

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?

Copy link
Contributor

@mqudsi mqudsi Oct 12, 2022

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.

(aliases)))'

function __fish_clj_aliases -V bb_helper
command -q bb
Copy link
Member

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

@faho faho merged commit c3052a6 into fish-shell:master Oct 14, 2022
@faho
Copy link
Member

faho commented Oct 14, 2022

Merged, thanks!

@faho faho added this to the fish 3.6.0 milestone Oct 14, 2022
@kthu
Copy link
Contributor Author

kthu commented Oct 17, 2022

Great! thanks

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants