17

I've created several bash aliases in Git Bash on Windows, to launch executables from the bash shell.

The problem I am having is that is seems the bash is waiting for an exit code before it starts responding to input again, as once I close the app it launched, it starts taking commands again.

Is there a switch or something I can include in the alias so that bash doesn't wait for the exit code?

I'm looking for something like this...

alias np=notepad.exe --exit
ctorx
  • 6,841
  • 8
  • 39
  • 53

3 Answers3

12

I confirm what George mentions in the comments:

Launching your alias with '&' allows you to go on without waiting for the return code.

alt text

With:

alias npp='notepad.exe&'

you won't even have to type in the '&'.


But for including parameters, I would recommend a script (instead of an alias) placed anywhere within your path, in a file called "npp":

/c/WINDOWS/system32/notepad.exe $1 &

would allow you to open any file with "npp anyFile" (no '&' needed), without waiting for the return code.

A script like:

for file in $*
do
  /c/WINDOWS/system32/notepad.exe $file &
done

would launch several editors, one per file in parameters:

npp anyFile1 anyFile2 anyFile3

would allow you

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yes, I get that, but what if I want to execute notepad to open a file as well as not waiting for a return code ? – ctorx Aug 20 '10 at 05:00
5

Follow the command with an ampersand (&) to run it in the background.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • Is it possible to include the & in the alias? For example, I want to do this.... alias np='notepad.exe $*&', where the $* is the parameters specified when the alias is used...(the filename to open). – ctorx Aug 20 '10 at 04:38
  • If you edit the git config file (`.git/config`) directly (in the `alias` section), you can probably add the `&` there. (You can't add it from the command line because it'll be interpreted as part of the command to set the alias, not part of the alias itself.) – Amber Aug 20 '10 at 06:23
3

I combined the solution of VonC and this https://stackoverflow.com/a/7131683/1020871 to get an alias that launches an executable and passes along the parameters without locking the git bash. Add the following to the .bashrc:

npp() {
    notepad++.exe $* &
}

startGitk() {
    gitk $* &
}
alias gitk=startGitk

Now I can open several files notepad++ like npp .gitignore build.gradle or gitk with custom arguments like gitk test -- .gitignore.

I had a similar alias for npp as for gitk but found that I could call the function directly. I can also call startGitk but it didn't work when I named it gitk.

Community
  • 1
  • 1
Love
  • 1,709
  • 2
  • 22
  • 30