Added examples from our discussion on quote escaping to https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows
selecting powershell as a platform for the clj command line is strange, so many problems because of this.
what about making a small GraalVM binary that is the replacement of the bash script
same code for all platforms, with fast startup time
hmmm… that sounds interesting @borkdude!
@carkh I think that windows is a bit of a foreign beast to most clojure users? What do people normally do?
Also I have enjoyed installing things via scoop. Would that work for clojure?
leiningen uses a .bat script, which works fine from everywhere, if you place it on the path
I guess that even works for Git Bash?
it does
Powershell also works, but I don’t understand the intricacies of it, like what it means to be a “command” instead of a script
Maybe GraalVM is overkill then?
and the escape-hell when you call it from non-powershell
yeah, it is not a nice experience.
I think one reason for Powershell was that writing .bat scripts is not fun. But with GraalVM you just get to write Clojure
Yeah I am waist deep in bash scripts right now. Not the worst thing, but not fun either.
Anyway, nice to have a starting point from which to get feedback and improve things.
IMO, a lot of the PowerShell issues are overblown. If you're in Git Bash feels like the bash script should get used instead. PowerShell has the momentum on Windows, so cmd isn't super compelling from my side. Also many of the quoting issues are tied to two things. A lack of "embrace the host" by trying to use more Posix style arguments (granted that's for consistency between Linux/Windows) that PowerShell doesn't handle as well. And that we call tools.deps inside the scripts which prints out arguments it expects you to put back on the cmd line when calling clojure. Those args work fine for bash, but require some translation for PowerShell.
If I ever have time I'd like to make a more native PowerShell feeling version of this, which wouldn't be fit for merging back in as it would drop consistency with Linux clj arguments.
I installed leiningen via scoop. It seems to support the 3 major shells:
PS C:\Users\lee> ls .\scoop\shims\lein*
Directory: C:\Users\lee\scoop\shims
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 6/4/2019 6:48 PM 104 lein
-a---- 6/4/2019 6:48 PM 59 lein.cmd
-a---- 6/4/2019 6:48 PM 270 lein.ps1
PS C:\Users\lee>
Isn’t that a more friendly approach?
are those scripts generated by lein or scoop?
hmmm… I do not know!
Let’s look at something you might be more familiar with:
PS C:\Users\lee> ls .\scoop\shims\clj-kondo*
Directory: C:\Users\lee\scoop\shims
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 6/4/2019 4:29 PM 7680 clj-kondo.exe
-a---- 6/15/2019 2:41 PM 275 clj-kondo.ps1
-a---- 6/15/2019 2:41 PM 67 clj-kondo.shim
PS C:\Users\lee>
I certainly did not write the .ps1
script
well scoop is doing a good deed then
hmmm… I not sure that scoop installed clj-kondo works from Git Bash.
lee@LEEREAD594C MINGW64 ~
$ clj-kondo
lee@LEEREAD594C MINGW64 ~
$
maybe do which clj-kondo
$ which clj-kondo
/c/Users/lee/scoop/shims/clj-kondo
and it does work from PS, cmd and WSL?
Yes to cmd and PowerShell. Have not tried WSL at all yet.
If we look at lein
shim:
#!/bin/sh
MSYS2_ARG_CONV_EXCL=/C cmd.exe /C "C:\Users\lee\scoop\apps\leiningen\current\lein.bat" "$@"
We see specific support for Git Bash (or Git Bash-like) shell.I don’t see anything specific here: https://github.com/ScoopInstaller/Main/blob/master/bucket/leiningen.json but maybe it does that because it’s a .bat script automatically
Looks like scoop generates it but not for exes for some reason: https://github.com/lukesampson/scoop/blob/6a39221036f3d52562d21c907a98b41fa748140e/lib/core.ps1#L393
I disagree with your premise that powershell has the momentum
the quoting issues are indeed the main issue
also we have trouble with tools trying to call into clj without hitting powershell at all
so no powershell, no clj command
in the end, we'll still need to have a bat or exe file to call into it
so what was the gain in having the thing implemented in powershell ?
It's a much better language than batch.
great, but now we have problems
my guess is that the real reason is the services provided by powerhsell
downloading, verifying
(didn't look very hard at the source)
but if this comes at that, fire up a c compiler or whatever language, anything .net is good too, and what we need from powershell is all included in .net
and .net is available on every windows computer
and it works from cmd
i mean a .net exe works from cmd
powershell was a bizarre choice
the solution to quoting issues is to generate a ps1 file, that way you deal with only 2 escaping syntaxes instead of the 3 (java, poweshell and your shell)
i have this very brittle batch file that at least let tools call into clj
it is brittle because it's not using a temp file (there is no good facility in cmd for that) for the launch.ps1 script
also the quote escaping was only worked on until it was "working for me", not many tests were made
i have the same code for clj.cmd and clojure.cmd
@borkdude i like your idea about making a graalvm executable