cygwin + console2: running cygwin bash with startup dir

12,737

Solution 1

As for the last bullet point, edit your ~/.bashrc and add a cd command at the end.

Instead of that, you can try this for your first bullet point: If your Console2 configuration to start Bash looks something like this:

bash --login -i

change it to:

bash --login -i -c 'cd somdir; exec bash'

Solution 2

I was having the same problem, saw your post, and then found this answer:

  1. Run the Setup.exe Cygwin installer and add the "chere" package
  2. In Console2, add a new tab called "Bash" with a shell path of "C:\cygwin\bin\bash". See screenshot.
  3. Finally, add the following to the registry: Code:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin Here...]

[HKEY_CLASSES_ROOT\Directory\shell\Open Cygwin Here...\command] @="\"C:\Program Files\Console2\Console.exe\" -t Bash -r \"/bin/xhere /bin/bash.exe '%L'\""

Found this solution at: http://www.e-texteditor.com/forum/viewtopic.php?p=8884

Solution 3

  • In Cygwin installer add "chere" package (contains /bin/xhere script)
  • Use the following shell command in Console2 settings:

    C:\cygwin\bin\bash.exe -c '/bin/xhere /bin/bash'

The shell will run in the current working dir or in the specified "Startup Dir".

Solution 4

I had some problems with some with the approaches above (Console2 window screwed up when using c:\cygwin\bin\bash.exe as shell, xhere not reflecting my actual working dir).

So I created this batch file and used it as Console2's shell:

C:\cygwin64\cygbash.bat:

C:\cygwin64\bin\bash --login -i  -c "/bin/xhere /bin/bash `cygpath -d '%CD%'`"

Solution 5

I tried variations of all the above, but none worked. This is what worked for me using Console2 v2.00.148:

1)..Copy the Cygwin.bat to a new file: Cygbash.bat.

2)..Replace the last line to be this: bash --login -i -c 'cd /cygdrive/c/; exec bash'

3)..Go into Console2 settings and change the shell to point to this new Cygbash.bat file.

The above will start Console2 in the root of your C drive. fyi - I'm the original poster, just forgot to login to my account first.

Share:
12,737
crispy
Author by

crispy

Frontend Developer and Project Manager at Zweitag

Updated on June 13, 2022

Comments

  • crispy
    crispy almost 2 years

    I am using Console2 as a bash wrapper on Windows. Most importantly, it enables me to start up a new bash tab in a predefined project directory.

    Now I would like to replace the Windows command line by a Cygwin bash. However, the "Startup Dir" setting in Console2 is not respected by Cygwin.

    Basically, I see three solution approaches:

    • Figure out how the Console2 setting has to look like so that the Cygwin bash respects it
    • Add a startup parameter to the Cygwin bash, setting the startup directory
    • Automatically run a script after bash startup that changes the directory

    Searching around in Cygwin's documentation and the rest of the Internet, I could not find a solution to any of those approaches. I could imagine that the solution is trivial to someone else, though. :)

    environment: Win XP, Console 2.00.146, Cygwin 1.7.7, GNU Bash 3.2.51(24)

  • crispy
    crispy over 13 years
    For the first solution, I added cd /cygdrive/c/projects to ` ~/.bashrc`, which has not been executed. Your second solution works, however, after 5 trys. Apparently, it is a necessity to use POSIX paths.
  • AndroidGuy
    AndroidGuy about 11 years
    Great answer. I can now start Console2 from Windows Explorer and it starts in the right directory. I still had to change the start drive in Console2 settings for when I start it outside of Windows Explorer.
  • Jon
    Jon over 8 years
    This works great, however if your path has spaces in it you'll need to add -d after cygpath, so instead use something like C:\cygwin64\bin\bash --login -i -c "/bin/xhere /bin/bash `cygpath -d '%CD%'`"
  • Martin Lütke
    Martin Lütke over 8 years
    I added your suggestion, Thank you.
  • ABC123
    ABC123 over 8 years
    I am using Console2 v2.00.148 and tried the accepted answer without success. This answer worked for me.
  • Federico Motta
    Federico Motta about 8 years
    Great answer, thank you. Worked perfectly on latest Console2 version as of this comment.