How do I configure Console2/Git Bash to run different scripts in different tabs?

Tag: git , bash , console2 Author: answer1231 Date: 2011-08-23

Firstly, my apologies for possibly incorrect terminology. I'm coming at this from a windows background and have only Windows and DOS knowledge with which to express my needs.


I am using Console2 to run Git Bash in 2 different tabs.

These tabs are setup to start in different working directories so as to default to working against 2 different repositories.

I have created a bunch of aliases to simplify the way I use GIT. These currently reside in my .bash_profile in my user folder.

The .bash_profile appears to be the linux equivalent of an old DOS autoexec.bat file. As such my aliases are setup for any tab which launches the git sh.exe.

I have been told that if I put the hg.exe (mercurial) on the path, then I would be able to use both hg and Git In this way. This proved to be correct.

What are my goals

I would like to be able to configure different tabs to work with different aliases.

In this specific case, I'd like to be able to setup an HG tab which still runs Git Bash (sh.exe), but which initializes a different set of aliases.

I believe I need to

  • Create a different "bat file" for each set of aliases.
  • Configure Console2 to use different "bat files" as autoexec for different tabs.

The Question

How do I tweak a setup Console2 tab (that currently launches sh.exe) so that it passes the name of a "command" file to run on startup?

Other Answer1

You can pass the name of a script to bash.exe and it'll run it. Bear in mind though that bash will expect the path to be in the UNIX style - for example instead of C:\temp\ it will want it like so /cygdrive/c/temp/

More information on invoking bash in the bash manual.

(You can use cygpath.exe to automate this translation if you want. I have an example on my blog.)

Update Sounds like you want to use --init-file or --rcfile and specify startup commands there.


Passing a file name does indeed seem to execute that file. However it seems to cancel the interactive nature of the shell and therefore exists when it has completed the script. I was hoping to use the script as a initialization for my session.
FWIW I'm currently styarting up using "C:\Program Files (x86)\Git\bin\sh.exe --login -i ~/"
Tried "C:\Program Files (x86)\Git\bin\sh.exe --login -i --init-file ~/" but this causes an immediate exit also. Indeed this time the script is not even executed. I verified it was executed the previous time by having it pause mid way through via a read command.
Try --rcfile instead.
also tried --rcfile. Same effect as --init-file. Essentially the shell just quits having apparently done nothing :(

Other Answer2

Makes more sense IMHO to write the aliases so that they behave differently in different environments. The behavior selector could be the current directory's name, or the presence of a flag file in the current directory; the alias or script file could contain this code, or the startup script could source different files, or simply set up the PATH differently depending on the selector.

Like this; in your .bashrc, add

test -e .git && . ~/bin/
test -e .hg && . ~/bin/

or like this;

test -e .git && PATH=~/bin/git:$PATH   # put co for git in ~/bin/git/co
test -e .hg && PATH=~/bin/hg:$PATH     # and ditto for ~/bin/hg/co

or like this;

test -e .git && VC=git

and then on the command line, you can set VC=hg at any time, provided your scripts (or aliases; but I would recommend functions, or scripts) look something like

case $VC in
  git) git --gobble=gook "[email protected]";;
  hg) hg bbq a/c "[email protected]";;
  *) echo "err um uh" >&2 ;;

This also depends on how much shared code you have in the aliases; does the hg alias for something look very different from the git alias for something? Then maintain them separately. Or encapsulate the shared code in a common source file used by both.


i have some 20-30 different aliases so far and I'm building more all the time. What you suggest might well work but it does introduce a lot of work to maintain these aliases, some of which don't have equivalents across different environments. In short it seems overly complex and hard to maintain.
On the contrary, modularizing it makes it easier, not harder. I'll update with some examples.
I'm interested to see such examples, but your original point seems to suggest a single set of aliases that understand their environment rather than multiple sets of aliases that I was after. Maybe I'm misunderstanding you, but your original suggestion seems less modular than mine?

Other Answer3

The following works for me using Console2. It uses Cygwin's bash shell and the .bash_profile in my cygwin $HOME directory.

<path_to_cygwin>\bin\bash.exe --login -i -c "cd /cygdrive/c/Cygwin/home/<username>; exec /bin/bash --init-file .bash_profile

Just replace .bash_profile with the file you want to source when the shell starts (and obviously use your own username and paths).

Other Answer4

Use console2 as wrapper with tabs. Here is an article for setting up