Start MSYS in current folder

9

2

I have MinGW/MSYS on Windows, and can't figure how to start MSYS shell in folder I'm working in.

For example, in Windows console I'm working in folder c:\temp and if I call MSYS (msys.bat) it opens new console window in some fixed location, representing my home folder.

How to change this msys.bat file, so that MSYS shell opens in current working folder (or changes to it, after start)?

zetah

Posted 2013-06-13T22:56:30.530

Reputation: 506

Can you include the contents of that batch file in your question? – Karan – 2013-06-13T23:41:43.240

Sure: https://github.com/msysgit/msysgit/blob/master/msys.bat

– zetah – 2013-06-13T23:57:38.663

1Unless I missed something I don't see a path being set anywhere in that batch file. My guess is that rxvt/bash are starting up in their default dirs as per their config files. You might be able to pass your current dir (%cd%) to them somehow, but I'm not sure. – Karan – 2013-06-14T00:08:47.083

Yep, that's what I'm looking for: when calling bash instruct it to change in current working folder under Windows. Cygwin has similar option – zetah – 2013-06-14T00:21:31.700

Answers

5

I'm not sure what version of msysgit you are using, but for me calling msys.bat does not change the current directory. If you see the directory being changed, check the etc/profile file in the msysgit directory for cd commands. As this file gets executed when a login shell is started it might be the cause for you to always land in your home directory.

sschuberth

Posted 2013-06-13T22:56:30.530

Reputation: 226

3Yes, the last line in that file (...\mingw\msys\1.0\etc\profile on my system) is cd "$HOME". If you comment that out bash will start in the current folder, then it's easy enough to type cd to go to the home folder. – Brian Burns – 2014-07-08T09:51:56.630

4

As others have pointed out, msys.bat will issue a cd "$HOME" from etc/profile. Setting the HOME environment variable to . gives me a mingw shell with the correct working directory.

set HOME=.
C:\MinGW\msys\1.0\msys.bat

Marcel Greter

Posted 2013-06-13T22:56:30.530

Reputation: 41

1

You can create a bash file and pass arguments to the msys2_shell.cmd to start anywhere you want it to be.

msys2_shell.cmd -where "home/name/esp"

Brandan

Posted 2013-06-13T22:56:30.530

Reputation: 11

0

If you want to run it in the folder you are working in, and you are working in that folder regularly, you can add a line to the end of .bash_profile in your home directory.

cd /c/temp

This command will be ran each time you log into the terminal. You can get elaborate and source a file if you have multiple commands you want to run, e.g.

. ~/etc/start_script . ~/etc/start_script2

This is especially useful if you already have your .bashrc configured and or don't really want to use an alternate HOME path.

Brian Thomas

Posted 2013-06-13T22:56:30.530

Reputation: 161

0

In case the modifying of etc/profile (commenting out of cd "$HOME" like in first answer) is undesirable for some reason, this could do the job:

# in mingw:
%SystemDrive%\mingw\msys\1.0\bin\sh.exe --login -i -c "cd '%TEMP%'; $SHELL"
# msys in root:
%SystemDrive%\msys\bin\sh.exe --login -i -c "cd '%TEMP%'; $SHELL"

This example would start msys shell in /tmp directory.

sebres

Posted 2013-06-13T22:56:30.530

Reputation: 26