Git Bash:通过别名启动应用程序而无需挂起 Bash(Windows)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3528020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git Bash: Launch Application via Alias without hanging Bash (WIndows)
提问by ctorx
I've created several bash aliases in Git Bash on Windows, to launch executables from the bash shell.
我在 Windows 上的 Git Bash 中创建了几个 bash 别名,以从 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.
我遇到的问题是 bash 在开始再次响应输入之前似乎正在等待退出代码,因为一旦我关闭它启动的应用程序,它就会再次开始接受命令。
Is there a switch or something I can include in the alias so that bash doesn't wait for the exit code?
是否有一个开关或我可以在别名中包含的东西,以便 bash 不等待退出代码?
I'm looking for something like this...
我正在寻找这样的东西......
alias np=notepad.exe --exit
采纳答案by VonC
I confirm what Georgementions in the comments:
我确认乔治在评论中提到的内容:
Launching your alias with '&' allows you to go on without waiting for the return code.
使用“ &”启动别名允许您继续操作而无需等待返回码。


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":
但是对于包含参数,我建议将脚本(而不是别名)放置在路径中的任何位置,在名为“ npp”的文件中:
/c/WINDOWS/system32/notepad.exe &
would allow you to open any file with "npp anyFile" (no '&' needed), without waiting for the return code.
将允许您使用“npp anyFile”(不需要“ &”)打开任何文件,而无需等待返回码。
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
会让你
回答by Amber
Follow the command with an ampersand (&) to run it in the background.
按照带有与号 ( &)的命令在后台运行它。
回答by Love
I combined the solution of VonC and this https://stackoverflow.com/a/7131683/1020871to get an alias that launches an executable and passes along the parameters without locking the git bash. Add the following to the .bashrc:
我结合了 VonC 的解决方案和这个https://stackoverflow.com/a/7131683/1020871来获得一个别名,它启动一个可执行文件并传递参数而不锁定 git bash。将以下内容添加到 .bashrc:
npp() {
notepad++.exe $* &
}
startGitk() {
gitk $* &
}
alias gitk=startGitk
Now I can open several files notepad++ like npp .gitignore build.gradleor gitk with custom arguments like gitk test -- .gitignore.
现在我可以打开多个文件 notepad++npp .gitignore build.gradle或 gitk 等自定义参数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.
我有一个与 gitk 类似的 npp 别名,但发现我可以直接调用该函数。我也可以调用 startGitk 但是当我将它命名为 gitk 时它不起作用。

