Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
myfile1
myfile2

C:\Users\Me\testdir>Cygwin

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

2 Answers 2

up vote 2 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.