如何在 git bash 终端(Windows 10)中打开谷歌浏览器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42522100/
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
how to open google chrome in git bash terminal (Windows 10)
提问by kost
I want to make a command like:
我想发出如下命令:
chrome "site.com"
which will make a google chrome window to pop up with the site instantly. Is there any way to achieve this?
这将使谷歌浏览器窗口立即与网站一起弹出。有没有办法实现这一目标?
回答by vijayinani
This worked for me on Windows 10 and using Git Bash.
这在 Windows 10 和使用 Git Bash 上对我有用。
start chrome www.google.com
回答by kost
start http://example.com
Opens the default browser with the URL.
使用 URL 打开默认浏览器。
Tested on Git Bash/Windows 10.
在 Git Bash/Windows 10 上测试。
回答by quantme
Here's what I'm using to open a URL or a file with Google Chrome into incognito modefrom Git bash (provided with Git for Windows):
这是我使用 Google Chrome从 Git bash(随Git for Windows提供)以隐身模式打开 URL 或文件的方法:
1. Open System Variables
1. 开放系统变量
- Hit
+Rat the same time to get command prompt.
- Then type
sysdm.cpl
and hit the Enterkey.
- 命中
+R在同一时间得到命令提示符。
- 然后键入
sysdm.cpl
并按下Enter键。
- Go to
Advanced
1and selectEnvironmental Variables
2 - Select
Path
3fromSystem variables
and click onEdit
button4.
- 转到
Advanced
1并选择Environmental Variables
2 - 从中选择
Path
3System variables
并单击Edit
按钮4。
Keep this window opened (while get thechrome.exe
folder path).
保持此窗口打开(同时获取chrome.exe
文件夹路径)。
2. Get the chrome.exe
folder path
2.获取chrome.exe
文件夹路径
Right click (or left if you have your mouse as left-handed) the Chrome icon5(the one you use to open it) and select Properties
7. Usually this method opens more Chrome actions so locate Google Chrome
option6and right-click on it and click on Properties
7.
右键单击(或左键,如果您的鼠标是左撇子)Chrome 图标5(您用来打开它的图标)并选择Properties
7。通常此方法会打开更多 Chrome 操作,因此找到Google Chrome
选项6并右键单击它并单击Properties
7。
On the Shortcut
8tab select the folder path from Start in:
9(Commonly%programfiles(x86)%\Google\Chrome\Application
)
在Shortcut
8选项卡上,从Start in:
9(通常%programfiles(x86)%\Google\Chrome\Application
)中选择文件夹路径
3. Adding Google Chrome folder path to Environment variables
3. 添加谷歌浏览器文件夹路径 Environment variables
Click on the New
button10from previously opened Edit environment variable
window and paste the Google Chrome folder path into the new added line11(delete the double quotes if exist at the beginning or the end of the path) and click on all the OK
buttons from the opened windows.
单击先前打开的窗口中的New
按钮10Edit environment variable
,并将 Google Chrome 文件夹路径粘贴到新添加的第11行(如果路径开头或结尾存在双引号,请删除),然后单击OK
打开的窗口中的所有按钮。
4. Add custom command to bash
4. bash 添加自定义命令
Open the Git bash terminal and edit (or create) the .bashrc
file with your prefered text editor (Visual Studio code in this example)
打开的Git的bash终端和编辑(或创建).bashrc
与您喜欢的文本编辑器文件(在这个例子中Visual Studio代码)
code ~/.bashrc
Append the code from below. You can rename the function name (chromeIt
in this example) to your needs.
从下面附加代码。您可以根据需要重命名函数名称(chromeIt
在本例中)。
# Open google Chrome
function chromeIt {
if [ -z "" ]; then
# display usage if no parameters given
echo "Usage: chromeIt <file_name>|<url>"
else
if [ -f "" ] ; then
chrome --incognito $(pwd)/
else
chrome --incognito
fi
fi
}
If you don't want incognito mode remove the --incognito
parameter.
如果您不想隐身模式,请删除该--incognito
参数。
Very important note:Verify that your line ending is set as UNIX (LF)12. If you don't know how to do it search into google.
非常重要的注意事项:验证您的行尾是否设置为 UNIX ( LF) 12。如果您不知道如何操作,请搜索google。
Save the .bashrc
file and reload it (using the Git bash terminal):
保存.bashrc
文件并重新加载它(使用 Git bash 终端):
source ~/.bashrc
or you can use the shorter versionof the command:
或者您可以使用该命令的较短版本:
. ~/.bashrc
Close the Git bash terminal window or enter exit
and re-open it.
关闭 Git bash 终端窗口或输入exit
并重新打开它。
Try to open a URL:
尝试打开一个 URL:
chromeIt google.com
or a file:
或文件:
chromeIt index.html
I hope it works for you.
我希望这个对你有用。
回答by PsychoX
You can use explorer.exe
that can open URL in default browser:
您可以使用explorer.exe
可以在默认浏览器中打开 URL:
explorer.exe "https://www.google.com/"
Therefore there is a weird bug: URL should not contain ?
, so:
因此有一个奇怪的错误: URL 不应包含?
,因此:
explorer.exe "https://www.google.com/search?q=foo+bar"
will fail, and you need to use:
会失败,你需要使用:
explorer.exe "https://www.google.com/search?q=foo+bar&\""
to work around.
解决问题。
By the way, I created bash function to open up Google page:
顺便说一下,我创建了 bash 函数来打开 Google 页面:
urlencode ()
{
echo | sed -e 's:%:%25:g' -e 's: :%20:g' -e 's:<:%3C:g' -e 's:\[:%5B:g' \
-e 's:>:%3E:g' -e 's:#:%23:g' -e 's:{:%7B:g' -e 's:\*:%2A:g' \
-e 's:}:%7D:g' -e 's:|:%7C:g' -e 's:+:%2B:g' -e 's:\:%5C:g' \
-e 's:/:%2F:g' -e 's:?:%3F:g' -e 's^:^%3A^g' -e 's:\!:%21:g' \
-e 's:@:%40:g' -e 's:=:%3D:g' -e 's:&:%26:g' -e 's:$:%24:g' \
-e 's:;:%3B:g' -e 's:~:%7E:g' -e 's:`:%60:g' -e 's:\^:%5E:g' -e 's:\]:%5D:g'
}
google ()
{
local a="$(urlencode "$(echo "$@")")"; a="${a// /+}";
explorer.exe "https://www.google.com/search?q=${a// /+}&\""
}
alias ggle='google'
alias g='google'
You can use it as follows:
您可以按如下方式使用它:
g site:cppreference.com c++ empty string view
I find it quite useful, especially while coding ;)
我发现它非常有用,尤其是在编码时;)
Tested on Bash on Windows (Ubuntu 16.04.3 LTS; GNU bash, wersja 4.3.48).
在 Windows 上的 Bash(Ubuntu 16.04.3 LTS;GNU bash,wersja 4.3.48)上测试。
回答by kalenpw
This should do the trick. I can't test on Windows 10 but works fine on bash in Ubuntu
这应该可以解决问题。我无法在 Windows 10 上进行测试,但在 Ubuntu 中的 bash 上运行良好
google-chrome http://www.google.com
google-chrome http://www.google.com
回答by skjoshi
You have few options here:
您在这里有几个选择:
- Add the installation path of Google Chrome to your system path or user path. After that in your command prompt or bash shell, you can just type
chrome "google.com"
. For me it isC:\Program Files (x86)\Google\Chrome\Application
. This postexplains it. - Provide complete path for the chrome.exe file in your command prompt. For the above mentioned path, the command will be
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" google.com
. - One more option will be you can alias the complete path of exe in bash as chrome and then use it.
- 将谷歌浏览器的安装路径添加到您的系统路径或用户路径。之后,在您的命令提示符或 bash shell 中,您只需键入
chrome "google.com"
. 对我来说是C:\Program Files (x86)\Google\Chrome\Application
。这篇文章解释了它。 - 在命令提示符中提供 chrome.exe 文件的完整路径。对于上述路径,命令将为
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" google.com
. - 另一种选择是您可以将 bash 中 exe 的完整路径别名为 chrome,然后使用它。
Please comment if you need more details.
如果您需要更多详细信息,请发表评论。