Alasdair Morrison Alasdair Morrison - 10 months ago 92
Bash Question

Open git bash shell window, execute command and remain after term signal

I have a batch file that sets up my environment by opening a number of "git bash" shell windows. This works perfectly apart from one annoying feature where if you press Ctrl C (or send any other Term signal) the whole bash window will close.

I want the window to behave as if it has been opened normally and so when it receives a term signal it goes back to the bash prompt.

Here is the current contents of my setup.bat file:

cd \project\
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login -i -l -c "source && mvn spring-boot:run"
cd \project2\
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login

Note that the first start command runs maven and when i want to restart the command (press Ctrl+C) it closes the whole window.
The second start command creates a new bash window in that directory which works like a normal bash window even with Ctrl+C, BUT I want it to have run a command at the start.

Is this possible?
Many thanks for all your help


Something like this might work for you:

cd \project\
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login -i -l -c "sh -c 'source && mvn spring-boot:run; exec sh'"

The trick is wrapping the command in:

sh -c '...; exec sh'

Where sh is your shell, might be bash.

You might actually to able to just suffix each command with: exec sh, eg:

start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login -i -l -c "source && mvn spring-boot:run; exec sh"