How do I configure ConEmu to run Cygwin Bash?

43

17

I created a new task

{Bash}

passed my home directory

/dir "C:\Users\TMB\"

and added bash as an application

C:\cygwin\bin\bash.exe

When I open Bash, it is unable to use the basic UNIX/Cygwin utilities. How do I configure ConEmu to run Cygwin Bash?

TMB

Posted 2013-05-03T18:52:23.930

Reputation: 611

What ConEmu version you are trying? Also, not all bash versions supports working directory. Git bash - can, as I remember. – Maximus – 2013-05-03T20:39:30.190

I couldn't figure out how to set me working directory in my bash profile, but I think I found a more general solution below the marked answer. – TMB – 2013-05-04T05:44:53.230

ConEmu x64 120727c.x64 – TMB – 2013-05-04T05:46:25.657

With "working directory" I mean one you specify with /dir switch. BTW, have you read this answer? http://superuser.com/a/482340/139371

– Maximus – 2013-05-04T09:33:27.227

Answers

49

This might helps others.

It looks like version 140310 of ConEmu automatically detects CygWin Bash.

If you've installed Cygwin after you installed ConEmu, you'll need to Reload... your list of Tasks.

  1. Go to Settings... (Win + Alt + P)
  2. Navigate to your list of Tasks (Startup > Tasks)
  3. Click on the Reload... button.

You should now see {CygWin bash} as one of your options in the list of predefined tasks:

Screenshot of CygWin bash in ConEmu

PS -- If this method doesn't work, try resetting your ConEmu settings (click the Reset... button at the bottom of your Settings window).

FilmiHero

Posted 2013-05-03T18:52:23.930

Reputation: 606

3For me clicking the Add default tasks... button (right above the Reload button) did the trick... – Hanan N. – 2014-06-26T19:17:31.337

9Note that sh.exe won't source your .bashrc; only bash.exe will do that. So I'm using the command %SystemDrive%\cygwin64\bin\bash.exe --login -i – John Prior – 2014-09-15T15:32:06.837

@JohnPrior's comment is actually very helpful. The PATH variable was all wrong when using sh.exe, but with bash.exe it can now actually find my applications. – flungo – 2014-11-05T19:06:02.283

I found that if I wanted to have the default tab start bash, I had to select the {Bash} task on the Startup settings (one level above Tasks). – carl.anderson – 2017-01-04T15:38:18.310

2And if Reloading and Resetting don't work, I guess we could enter the path, command, and options as shown in your screen shot. – TMB – 2014-03-29T02:16:46.657

%SystemDrive%\cygwin64\bin\sh.exe --login -i for me on 140304 on the Preview Channel. – TMB – 2014-03-29T02:22:34.563

7

or instead of

C:\cygwin\bin\bash.exe

use

C:\cygwin\Cygwin.bat

Yura

Posted 2013-05-03T18:52:23.930

Reputation: 171

I think that's indeed the simplest way. – laurent – 2013-12-27T16:35:10.537

6

Ensure that Bash is receiving a sensible value for $PATH; usually it inherits that from whatever calls it, but ConEmu is a Windows application, so all it's going to provide is whatever you have set for %Path%. Generally that doesn't include the Cygwin path directories, so Bash doesn't know where to look for ls, &c.

The way I'd solve this would be to, via whatever means ConEmu offers for doing so, pass --login -i as command line arguments to Bash; this will tell it you're running it as an interactive login shell, so it will read /etc/profile, ~/.profile, and ~/.bashrc on start. In my experience, that's been enough to give it a sensible $PATH; if that doesn't work for you, you could specify it explicitly with a line like PATH=/bin:/usr/bin:/usr/local/bin:[...]:$PATH in your ~/.bashrc.

Aaron Miller

Posted 2013-05-03T18:52:23.930

Reputation: 8 849

This got me the utilities I was looking for next I wanted to point to my normal windows home directory not /cygdrive/c/cygwin/home so I deleted home and made a junction with mklink -J home C:\Users in cmd.exe – TMB – 2013-05-04T05:43:26.333

3Glad it did the job for you. I never thought about using a junction to point ~ at c:\users\me, but I once did it with a symlink, and from that experience I give you the following warning: if you ever need to run ComboFix to clean up a malware infestation on your machine, it will blow away any files in c:\users\you. I lost everything in my home directory that way once, and my newest backup was a week old. Don't make the same mistake I did! – Aaron Miller – 2013-05-04T06:48:57.967

2

This is my way

Create a new task in ConEmu with following command

set HOME=C:\Home & "C:\Home\Applications\cygwin64\bin\mintty.exe" -i /Cygwin-Terminal.ico -

Buzz

Posted 2013-05-03T18:52:23.930

Reputation: 121

Your solution works, and I like having the mintty.exe interface, but can you explain why this works? Especially, what is the "&" doing here? – Dr. Koutheir Attouchi – 2016-12-23T09:16:31.387

0

To make Cygwin commands available from bash, regardless of how you run it, as well as from cmd or any other shell, make sure your Path environment variable has Cygwin's bin directory added.
Go to Control Panel > System and Security > System (standard hotkey Win+Pause), then Advanced system settings > Environment variables. For all users, edit the system Path variable, just for your user - edit (create if it doesn't exist) the user Path variable.
Assuming cygwin is installed at C:\cygwin (might be cygwin64 for 64-bit Cygwin), add C:\cygwin\bin to the Path. Be aware that if you use the system Path variable, if you add Cygwin's bin in the beginning, some Cygwin's command will shadow built-in ones (e.g. Cygwin's find will be used instead of Windows' find). I prefer to do so, but if you don't, add Cygwin's bin at the end of your Path.

Since most other answers also talk about ConEmu setup, I'll give my personal opinion as well.

I prefer to run a non-login shell. For example, in Linux you get a login shell when you log in at the text console or via ssh, and a non-login interactive shell when you open a terminal emulator (xterm, konsole, etc.).

My {Bash} task has /dir "%CD%" task parameters to set the working directory to the current tab's working directory (e.g. if the bash task from Far). The command to start bash:
%ConEmuDrive%\cygwin\bin\bash.exe -new_console:C:"%ConEmuDrive%\cygwin\Cygwin.ico"

Notice --login -i options are omitted, shell will start as a non-login interactive shell (since it has no non-option arguments and without the -c option, and it's stdin and stdout are connected to terminals, refer to INVOCATION section of bash's manpage for more explanation). It will read and execute commands from the user rcfile ~/.bashrc (not /etc/profile or ~/.bash_profile as a login shell would, thus you don't need to set CHERE_INVOKING=1 which is only relevant with regards to /etc/profile). So put your user aliases, shell options, extra environment variables etc. to ~/.bashrc, where they rightfully belong.

Gene Pavlovsky

Posted 2013-05-03T18:52:23.930

Reputation: 356

0

I know thats a pretty old question but I wanted to share this anyway:

To start the bash within a specific working directory just set the command for example to SET CHERE_INVOKING=1 & "C:\cygwin\bin\bash.exe --login -i" -cur_console:t:"cygwin terminal" and specify the working directory normally via /dir "..." as described here.

Felix Bayer

Posted 2013-05-03T18:52:23.930

Reputation: 101