scoop-clojure
scoop-clojure copied to clipboard
Shim without `cmd-` prefix?
After successfully running steps above, you should be able to run Clojure with following:
cljTo launch clojure from cmd.exe or tools like Emacs, you can use prepared shims:
cmd-clj cmd-clojure
Thanks for the project, it's useful. However I don't understand the above?
Under what context can I just run clj without the cmd- prefix?
Why aren't the shims written so that they work in the same way as osx and linux with clj being used from the command line?
Is it possible to add this as an option? Or is there a problem that this is averting?
Thank you.
Hi Daniel. I'm glad you find this project helpful.
Use clj and clojure whenever possible. Period. The requirement is that your current shell is Powershell. This should be the default in most, if not all, useful cases.
But if your shell is cmd.exe (aka Command Prompt), you won't be able to use clj and clojure because cmd.exe know nothing about Powershell scripts aliases, etc. So these shims serve the purpose of the bridge. They are just executables that run intermediary Powershell with proper parameters for you.
Try it yourself. Launch Command Prompt (cmd.exe) and try clj and see what happens. Then the same with cmd-clj.
If Emacs or VSCode launch a terminal with cmd.exe as a shell, these shims become handy.
Hope it answers your question.
Would it be possible to create a clojure.bat and clj.bat alongside cmd-clojure.exe and cmd-clj.exe? They would just contain something like @cmd-clojure %* and @cmd-clj %* respectively. I've been using a setup like this so I can run clojure and clj from cmd shell, and it's working pretty well for me so far.
@chadkennedyonline I understand your strugle, but I'm reluctant to add this. It's already confusing enough.
I read your case on Slack - and for other readers the use case is to launch clojure and clj commands from npm run scripts.
I was playing around a bit with this and I come with a nice tweak.
You can add clojure.bat and clj.bat to your npm project root and use it like this:
shelling $ ls
Directory: C:\Users\alesn\Projects\shelling
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 27.12.2021 18:50 15 clojure.bat
-a--- 27.12.2021 18:29 248 package.json
shelling $ cat .\clojure.bat
@cmd-clojure %*
shelling $ cat .\package.json
{
"name": "shelling",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clojure": "clojure"
},
"keywords": [],
"author": "",
"license": "ISC"
}
shelling $ npm run clojure
> [email protected] clojure C:\Users\alesn\Projects\shelling
> clojure
Clojure 1.10.3
user=>
On Unices your commands should work from their particular locations, on Windows it will pick the batch files first. Let me know if you like this proposal.
Hi @littleli! Thanks for the feedback! Clearly I'm just starting out on my Clojure adventure, and eager to learn!
I've essentially done exactly what you suggest, except clojure.bat and clj.bat live in the same folder as cmd-clj.exe and cmd-clojure.exe created by scoop (scoop\shims).
This has two important upsides for me:
- I can follow along with Clojure tutorials, books, etc that call for making calls to clj or clojure . As you mentioned in your comment above, this can already by done via PowerShell. Maybe I'm an oddball, but I much prefer the cmd prompt to PowerShell. As a beginner, I was quite confused when I couldn't find any solutions out there to simply run
clojureorcljfrom the cmd prompt. Clearly though, I must be in the minority on this, since no such packaged solution exists, as far as I can find. - Any Clojure project that has scripts in their
package.jsonthat callclojureorcljwill work. Under your proposal, I'd have to make these batch files for each project. Projects where this would be helpful.
So those are the upsides as I see them from my amateur perspective. Admittedly, I have no understanding of what all it's taken to get scoop-clojure working on Windows up to this point. But I don't understand when you say "it's already confusing enough". Would you mind explaining a bit more how adding these bat files alongside the shims would add to confusion?
I'm certainly very grateful that scoop-clojure exists, and for me, I'm perfectly happy to just use my 2 bat files as-is. But I am eager to learn if there are downsides to my approach.
@chadkennedyonline There are reasons...
I can't put random files to shim directory on my own. It's managed by scoop based on the config from manifest file. See "bin" section here: https://github.com/littleli/scoop-clojure/blob/9dabceb65f2a7799011f7025b0d761fb6cb8b54a/bucket/clojure.json#L20
ad 1) You can do this entirely in Powershell and it's what you should use. ad 2) Unfortunately yes. Until npm will be able to execute through powershell.
What you don't see is that clojure.bat and clj.bat would shadow powershell clojure alias.
Powershell users would then run cmd.exe just to issue cmd-clojure which would launch powershell again with Invoke-Clojure commandlet. Not very effective and who knows what breaks on the way. There is also quote escaping issue.
So yes, it's a small inconvenience with one (or two) .bat files copied over among projects once. But at least it's clear and relatively safe execution.
I may change my mind if I find better (non clashing) solution to this problem.
Thanks @littleli! I understand now.
Adding a little additional context here just for anyone with similar questions to my own:
-
clojureandcljwere originally available from the cmd prompt through this package. They were removed due to this issue: https://github.com/littleli/scoop-clojure/issues/5 . -
cmd-cljandcmd-clojurewere then added back in to try to provide something for cmd shell users, without breaking the powershell functionality
Moving forward, I'm going to investigate if npm or yarn can be forced to use powershell instead of cmd, either globally or (better) per project. A quick search shows it may be possible. If not, I'll stick to my 2 batch files. I'll probably move them into the project folder as suggested, so I'm not breaking anything that uses powershell.
EDIT: I can confirm that using scoop-clojure in its stock configuration, along with running yarn config set script-shell powershell.exe allowed me to run all the scripts in package.json just fine!
EDIT: I can confirm that using
scoop-clojurein its stock configuration, along with runningyarn config set script-shell powershell.exeallowed me to run all the scripts inpackage.jsonjust fine!
@chadkennedyonline This is cool, it definitely helps.
You actually don't even need yarn. You can setup npm accordingly with something like this:
npm config set script-shell "C:\\Program Files\\PowerShell\\7\\pwsh.exe"
(my case)
@littleli Do you think it's worth adding something about using ... script-shell ... to the README.md? Or is this enough of an edge case to not want to add additional clutter?
@chadkennedyonline @dmg46664 Hi guys. I just want to let you know something about this issue is baking for this Christmas.
@littleli Good to know! But don't feel any pressure from me. I was temporarily a PC user when I wrote this up and was waiting for the M1 to come out 😋 I've also seen how well WSL works for many clj use cases. Have a festive season!
ok, here we go. Current default method of getting Clojure on Windows is following:
scoop uninstall clojure
scoop install clj-deps
cmd-clojure and cmd-clj are gone, long live clj and clojure
A lot of thanks has to go to @borkdude for deps.exe and to @casselc for his work on msi installer which basically pushed me to resolve this.