2

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.

Background

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?

Rory Becker
  • 15,551
  • 16
  • 69
  • 94

4 Answers4

0

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).

Fish
  • 370
  • 1
  • 3
  • 11
0

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

milkovsky
  • 8,772
  • 4
  • 28
  • 32
0

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\myscript.sh it will want it like so /cygdrive/c/temp/myscript.sh.

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.

Duncan Smart
  • 31,172
  • 10
  • 68
  • 70
  • 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. – Rory Becker Sep 08 '11 at 10:36
  • FWIW I'm currently styarting up using "C:\Program Files (x86)\Git\bin\sh.exe --login -i ~/gitProfile.sh" – Rory Becker Sep 08 '11 at 10:39
  • Tried "C:\Program Files (x86)\Git\bin\sh.exe --login -i --init-file ~/gitProfile.sh" 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. – Rory Becker Sep 08 '11 at 11:02
  • also tried --rcfile. Same effect as --init-file. Essentially the shell just quits having apparently done nothing :( – Rory Becker Sep 08 '11 at 11:11
0

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/gitalises.sh
test -e .hg && . ~/bin/hgaliases.sh

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 "$@";;
  hg) hg bbq a/c "$@";;
  *) echo "err um uh" >&2 ;;
esac

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.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 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. – Rory Becker Sep 08 '11 at 11:25
  • On the contrary, modularizing it makes it easier, not harder. I'll update with some examples. – tripleee Sep 08 '11 at 11:32
  • 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? – Rory Becker Sep 08 '11 at 11:37