Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to set up Cygwin so that if I call Cygwin.bat from an arbitrary path using arbitrary Windows-native launching method (cmd.exe, Total Commander' command line), it will start bash prepared in that directory?

For example, if I run cmd.exe and do following (provided that Cygwin.bat is on my PATH):

C:\Users\Me>cd testdir

C:\Users\Me\testdir>dir /b


Cygwin window opens and I'm just where I left off:

me@here /cygdrive/c/Users/Me/testdir
$ ls
myfile1*  myfile2*

me@here /cygdrive/c/Users/Me/testdir

As you can see, when I get Cygwin prompt, I'm already at testdir, not at /home/me.

(More typical scenario where I'm going to use this is running Cygwin from Total Commander's command line, but I guess it should work the same.)

How to achieve this?

share|improve this question
'This' is what? How do you want to run Cygwin exactly? – Maximus Aug 17 '12 at 20:04
up vote 3 down vote accepted

I was able to hack something together for you. Put this in a batch file in your path (I called mine cygwin.bat, and called it by entering cygwin.bat):

@echo off
set pth=%CD:~2,99%
set pth=%pth:\=/%
set drv=%CD:~0,1%
set "fullpath=/cygdrive/%drv%%pth%"
C:\cygwin\bin\bash.exe --login -i -c "cd ""%fullpath%""; exec /bin/bash"
share|improve this answer
Works like charm, thanks! :) Wasn't able to make a version for "Cygwin Terminal" (using mintty.exe), but since I did not specify which terminal emulator to use, I may keep it for a separate Q. – Alois Mahdal Aug 27 '12 at 9:57

This simpler .bat file (.cmd in my case) is working fine for me:

c:\CygWin\bin\bash.exe --login -i -c "export CD='%CD%'; cd \"$CD\"; exec /bin/bash"

Tested working on:

  • CMD.
  • Total Commander.
  • Remote SSH session.
  • Start Menu --> Run (in this case it opens at C:\Users\Me).
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .