Using Leiningen in Git Bash on Windows
Asked Answered
N

2

6

So i installed Leiningen and git on windows. But git bash does not seem to find the lein command because it is based on a .bat file. It works in the windows command line. Is there any way to get the lein command to work in git bash?

Nyx answered 3/2, 2016 at 13:9 Comment(0)
C
11

First, I added the lein.sh script into ~/bin folder. This folder should be added in the path by GitBash itself. If it's not in PATH, you can add lein.sh to any folder that is in there or simply add ~/bin to your PATH. Something like:

PATH=$PATH:~/bin

You can set the following alias on "~/.bashrc" in your home directory to it easier to call Leiningen:

alias lein='lein.bat'

It's working fine with Leiningen 2.6.1 and Git Bash 2.8.0.

Carmichael answered 4/5, 2016 at 1:37 Comment(0)
I
0

If I go into git bash and type echo $PATH I see what seems like the same thing as when I type echo %PATH% from a dos console.

So I alter the Windows Path environment variable so it includes C:\programs\lein, which is where lein.bat is.

Back into git bash I type lein and get command not found. But if I type lein.bat I can see it is trying to run the file, presumably as if it were a shell script:

Chris@CHRIS-XPS ~
$ lein.bat
/c/programs/lein/lein.bat: line 1: @echo: command not found
/c/programs/lein/lein.bat: line 3: setLocal: command not found
/c/programs/lein/lein.bat: line 7: syntax error near unexpected token `('
/c/programs/lein/lein.bat: line 7: `if "%LEIN_VERSION:~-9%" == "-SNAPSHOT" ('

So you will be able to get further by dropping in lein.sh to replace lein.bat. Good to start with your own lein.sh that tries to only execute java -jar lein.jar -cp ... (I made that up but it should be possible to piece the correct command together from viewing the batch file (or the shell script)). In fact if your Windows hosted lein.sh can start any java program, it should also be able to start lein.

Interminable answered 3/2, 2016 at 17:4 Comment(2)
Unfortunatly im not familiar with bash. I actuall tried to hack together a shell script with the "cmd" command to simply execute the bat file, but that didnt work. So there is a selfhosted jar, that i can start via java -jar leiningen.Versionnumber-standalone.jar, which starts a repl. The problem is getting the commands to work. Every command like help,app, etc has a .clj file with the logic which are contained in the jar. But i cant decipher how the lein.bat actually forwards the parameters so the commands are loaded. So i dont know how to forward parameters in bash and then to the lein jar.Nyx
And how did it go running this command? Also just peeking in that file gives another suggestion, and that is to install Cygwin.Interminable

© 2022 - 2024 — McMap. All rights reserved.