Petra
Petra

Reputation: 41

Configuring Cygwin for ConEmu with different start directory

I am using ConEmu 64bit with Cygwin 64bit on a Windows 7 machine.

I don't want to set the working directory for cygwin in my .bashrc, as I like to setup more than one Task for Cygwin with different path parameters.

I set up the "home directory" in the task parameters:

\dir "D:\Downloads\Programming\Selenium\"

and added this line in the commands window:

C:\cygwin64\Cygwin.bat --login -i

Nevertheless Cygwin does not start in the "cygwinized" version of the given directory (/cygdrive/d/Downloads/Programming/Selenium) but in "normal" home directory of my user (~).

I only found howto's on how to add a new path in bashrc. Maybe one of you can enlighten me.

Upvotes: 4

Views: 5079

Answers (2)

Maximus
Maximus

Reputation: 10847

First of all, have you look at contents of your C:\cygwin64\Cygwin.bat? Why not?

@echo off
C:
chdir C:\cygwin64\bin
bash --login -i

Obviously, Cygwin.bat will never open bash in your desired dir.


Also, Cygwin ignores user defined startup directory! That is because cygwin always do cd "${HOME}" from /etc/profile script.

But, for example, bash from msysgit works properly.


Solution

However, /etc/profile script checks for CHERE_INVOKING environment variable before CD doing. So, the proper command line for starting cygwin will be:

set CHERE_INVOKING=1 & c:\cygwin64\bin\sh.exe --login -i

Another workarounds you may find in the project wiki page.

Upvotes: 5

Father Stack
Father Stack

Reputation: 524

I had a similar demand (opening a new Cygwin-Tab in the folder currently viewed in explorer via the context menu) and found the following solution:

As stated by Maximus the Cygwin-Bash is usually opened by C:\cygwin64\Cygwin.bat which includes the login process. My approach was to change the working directory through the login.

.bash_profile:

if [ -f "${HOME}/startup.sh" ] ; then
  source "${HOME}/startup.sh"
fi


startup.sh

cdc "D:\Downloads\Programming\Selenium\"
#cdc is a custom function, see .bashrc


.bashrc

cdc()
{
   # converts a double-quoted windows-path and changes directory to it
   p=$(cygpath -u "$1")
   cd "$p"
}

The login progress thus changes the path of you bash to the one you've set in startup.sh. You might of course just type a Cygwin-compatible path in startup.sh without using the custom-function of .bashrc. It's still quite useful, especially if you want to want to use a dynamic startup.sh.


More Dynamic-approach:

Create a Cygwin.bat in C:\opt\ConEmu\ConEmu with the following content:

Cygwin.bat

@echo off

C:
echo cdc %1 > C:\opt\cygwin64\home\%USERNAME%\startup.sh 

:: Your ConEmu-Task-definition here
C:\opt\ConEmu\ConEmu64.exe /Single /cmd {Cygwin}

This one writes a cdc-command followed by the path you provide into your startup.sh and starts an new instance of the ConEmu-Task Cygwin. The task itself does not do anything but starting an instance of Cygwin in my configuration:

ConEmu Task {Cygwin}

"C:\opt\cygwin64\Cygwin.bat"



I invocate the Cygwin.bat through the context-menu of the explorer. Another way would be to make a Windows-Shortcut pointing to Cygwin.bat with you path appended.

Upvotes: 0

Related Questions