Using Leiningen in Git Bash on Windows - windows

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?

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.

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.

Related

Git bash change into a directory and start a file

My default git bash starts on the C: drive and I often have to change into a project directory and start a file up.
Is there a way to cd into a directory and start a file all in one command using Git bash on Windows?
You should have a file .bashrc into your home directory. It should be under
C:\Users\login
Add the following line in the file: cd "projet_directory_full_path"
Open a new session and it should start on your project directory
Yes, you can directly start with cat command following with complete path using forward slashes as 'cat C:/Users/username/filename' and cd command also works in similar way.

UNIX command on Windows using Git Bash -- Error: "'C:\Program' is not recognized"

I just installed Git bash in order to run a UNIX command. I am trying to recreate a project starter which is using UNIX; it seemed there was no way for Windows to run a "grep" command without using something like Git bash.
I CD into the project folder directory
mboyl#DESKTOP-8R019P7 MINGW64 ~/lei_broker (master)
Then I run my command
$ heroku config:set SANITY_READ_TOKEN=$(grep SANITY_READ_TOKEN .env.development)
And am met with the error
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
What is going on here? 'C:\Program' is not included in my command.
My initial troubleshooting has recommended using a shell besides Git bash or setting an environment variable. My technical chops are limited, so if there is a simple Linux/UNIX syntax error I am making, please advise.
Matt
Posting as an answer since I need 50 Reps.
While I don't know what's inside the file .env.development, why not wrap all Windows paths with single-quotes & try?

Cygwin 'cd' command always tells me "No such file or directory"

When i login to the cygwin terminal and type:
cd "cygdrive/c/existing/path"
it tells me, "no such file or directory". i am sure the path exists... do i miss a special cygwin package, or do i have a false configuration? i am puzzled...
It behaves the same when i try to call the cygwin bash from a windows batch file.
what i basically want to do is creating a windows batch file which starts cygwin and executes a shell script with a specified working directory as its described in this blog post: http://blog.dotsmart.net/2011/01/27/executing-cygwin-bash-scripts-on-windows/
my batch file seems to work, it does the following command:
%_CYGBIN%\bash.exe --login "cd %_CYGPATH%" "./%_CYGSCRIPT%"
but cygwin won't execute the 'cd' command. The console output of my batch file is:
/usr/bin/bash: cd /cygdrive/c/existing/path: No such file or directory
cd '/cygdrive/c/existing/path'
# ^
# \
# --- need forward slash (/) before the "c"

How to add something to bash path without messing up existing bash commands?

I'm doing some Android development and want to access the command line tools from anywhere.
There wasn't an existing .bash_profile file in my home directory so I created one and added the following line:
export PATH="/Users/Me/desktop/Android/Android SDK bundle/sdk/platform-tools"
I can now access the Android tools from terminal, however the ls command has stopped working, though cd still works. I get
-bash: ls: command not found
What should I do to get it to work again (and why has ls stopped working but cd still works?).
Try:
export PATH=$PATH:"/Users/Me/desktop/Android/Android SDK bundle/sdk/platform-tools"
It will append to the current PATH your sdk directory.
As for the later question, it stopped working because you overwritten your PATH variable, so bash can't find your binaries. However cdis a builtin command (http://linux.about.com/library/cmd/blcmdl1_builtin.htm) it doesn't need a path to be located and executed.

Why can't Cygwin CVS read the CVS password file in a Ruby/Perl script?

On the Windows command line and cygwin bash I can execute the following without problems:
cvs login
cvs -Q log -N -rVersion_01_00
A ruby script in the same directory contains the following:
`cvs login`;
`cvs -Q log -N -rVersion_01_00`;
When I execute the ruby script on the Windows command line I get the following error:
cvs log: warning: failed to open /cygdrive/c/Documents and Settings/za100744/.cvspass for reading: No such file or directory
If I run the script in a cygwin bash shell I get the same output I would as when I type in the commands manually.
I have no idea as to what is going wrong. The path generated by the Ruby script is wrong since it is a cygwin path but it works correctly directly on the command line. I use cvs that came as part of cygwin:
which cvs
cvs is an external : C:\cygwin\bin\cvs.exe
Ruby is the one-click installer version:
which ruby
/cygdrive/c/Ruby/bin/ruby
It seems like cvs under Ruby can not resolve /cygdrive/c to c: but works OK from the cmdline.
Perl gives me exactly the same problem.
my $str = "cvs -Q log -N -r$cvs_tag|";
open(CVS_STATUS, $str) or die "\n##ERROR##";
It looks like either CVS can't create the file, or your path is wrong. Does the file .cvspass exist? If not, this page suggests you try creating an empty .cvspass file and then run your command. e.g. do
touch ~/.cvspass
If this doesn't help, then the problem is probably path related. There are a few possibilities; $HOME not set correctly, your home dir not matching what's in \etc\passwd, etc. See this tutorial for some troubleshooting steps that should help pin down the problem.
Using a windows native compiled CVS solves the problem. It is not ideal since I have to send a cvs executable with the script for users that has cygwin CVS but its better than nothing.
We had several problems with unix-, mixed- and windows-style paths in cygwin based perl scripts and built-in tools such as rsync. E.g. rsync can't handle wind-style paths. Use the tool "cygpath.exe" to adjust them correctly. Maybe it's the cause.

Resources