dundalek / closh

Bash-like shell based on Clojure
Eclipse Public License 1.0
1.61k stars 65 forks source link

Uberjar: some issue with auto-completion #92

Closed jeroenvandijk closed 5 years ago

jeroenvandijk commented 5 years ago

Using the new uberjar

When I type "(if" and subsequenty press I get the exception below. CTR-c get's me out of this error state again

$ (ifOct 09, 2018 10:33:12 AM org.jline.utils.Log logr
INFO: Error while finding completion candidates
java.io.IOException: Cannot run program "/scripts/completion/completion.fish" (in directory "/Users/jeroen/bin/closh"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at closh.zero.platform.process$shx.invokeStatic(process.clj:88)
    at closh.zero.platform.process$shx.invoke(process.clj:46)
    at closh.zero.platform.process$shx.invokeStatic(process.clj:49)
    at closh.zero.platform.process$shx.invoke(process.clj:46)
    at closh.zero.service.completion$get_completions_spawn.invokeStatic(completion.cljc:23)
    at closh.zero.service.completion$get_completions_spawn.invoke(completion.cljc:20)
    at closh.zero.service.completion$complete_fish.invokeStatic(completion.cljc:36)
    at closh.zero.service.completion$complete_fish.invoke(completion.cljc:33)
    at closh.zero.service.completion$complete_shell.invokeStatic(completion.cljc:81)
    at closh.zero.service.completion$complete_shell.invoke(completion.cljc:80)
    at closh.zero.frontend.rebel$clojure_completer$fn__2422.invoke(rebel.clj:54)
dundalek commented 5 years ago

Good catch, I totally forgot this might cause an issue. The thing is that shell completions are delegated to existing shells by calling wrapper scripts. So we need to bundle these into the uberjar as well and then somehow read them as resources.

jeroenvandijk commented 5 years ago

Ah cool. You can read files from the uberjar when you put things in resources (would have to test with boot-clj) and using (slurp (clojure.java.io/resource "path-in-resources-dir"))

jeroenvandijk commented 5 years ago

Ok this removes the problem:

$ pwd |> ((fn [x] (setenv "CLOSH_SOURCES_PATH" (first x))))

For a permanent solution, we could have an installation step that copies the resource dir from the uberjar to the directory where the jar is located. I've tested this approach [1] and that would work in combination with clojure.java.io/resource and slurp etc

What do you think makes most sense?

[1] https://stackoverflow.com/questions/22363010/get-list-of-embedded-resources-in-uberjar

dundalek commented 5 years ago

That PR is a good start to kick things off. I think with it it should be possible just to pass those scripts from resources into respective shells via stdin (without the need to save the contents anywhere to disk).