[英]how to open google chrome in git bash terminal (Windows 10)
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?
有没有办法实现这个目标?
这对我在Windows 10上使用并使用Git Bash。
start chrome www.google.com
Here's what I'm using to open a URL or a file with Google Chrome into incognito mode from Git bash (provided with Git for Windows ): 以下是我用来从谷歌浏览器打开URL或文件到Git bash的隐身模式 (随Git for Windows提供 ):
sysdm.cpl
and hit the Enter key. sysdm.cpl
并按Enter键。 Advanced
1 and select Environmental Variables
2 Advanced
1并选择Environmental Variables
2 Path
3 from System variables
and click on Edit
button 4 . System variables
选择Path
3 ,然后单击Edit
按钮4 。 Keep this window opened ( while get the chrome.exe
folder path ). 保持此窗口打开( 同时获取
chrome.exe
文件夹路径 )。
chrome.exe
folder path chrome.exe
文件夹路径 Right click ( or left if you have your mouse as left-handed ) the Chrome icon 5 ( the one you use to open it ) and select Properties
7 . 右键单击( 如果你的左手是鼠标,则左键 )Chrome图标5 ( 用于打开它的图标)并选择
Properties
7 。 Usually this method opens more Chrome actions so locate Google Chrome
option 6 and right-click on it and click on Properties
7 . 通常,此方法会打开更多Chrome操作,因此请找到
Google Chrome
选项6并右键单击它,然后单击Properties
7 。
On the Shortcut
8 tab select the folder path from Start in:
9 ( Commonly %programfiles(x86)%\\Google\\Chrome\\Application
) 在
Shortcut
8选项卡上,从Start in:
选择文件夹路径Start in:
9 ( 通常 %programfiles(x86)%\\Google\\Chrome\\Application
)
Environment variables
Environment variables
Click on the New
button 10 from previously opened Edit environment variable
window and paste the Google Chrome folder path into the new added line 11 (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. 单击之前打开的
Edit environment variable
窗口中的“ New
按钮10 ,然后将Google Chrome文件夹路径粘贴到新添加的行11中 (如果存在于路径的开头或末尾,则删除双引号)并单击所有“ OK
按钮从打开的窗户。
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 "$1" ]; then
# display usage if no parameters given
echo "Usage: chromeIt <file_name>|<url>"
else
if [ -f "$1" ] ; then
chrome --incognito $(pwd)/$1
else
chrome --incognito $1
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 . 非常重要的注意事项:验证您的行结尾是否设置为UNIX( LF ) 12 。 If you don't know how to do it search into google .
如果您不知道该怎么做,请搜索谷歌 。
Save the .bashrc
file and reload it (using the Git bash terminal): 保存
.bashrc
文件并重新加载(使用Git bash终端):
source ~/.bashrc
or you can use the shorter version of the command: 或者您可以使用命令的较短版本 :
. ~/.bashrc
Close the Git bash terminal window or enter exit
and re-open it. 关闭Git bash终端窗口或进入
exit
并重新打开它。
Try to open a URL: 尝试打开一个网址:
chromeIt google.com
or a file: 或文件:
chromeIt index.html
I hope it works for you. 我希望这个对你有用。
You can use explorer.exe
that can open URL in default browser: 您可以使用可以在默认浏览器中打开URL的
explorer.exe
:
explorer.exe "https://www.google.com/"
Therefore there is a weird bug: URL should not contain ?
因此有一个奇怪的错误:URL不应该包含
?
, so: ,所以:
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 $1 | 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)。
start http://example.com
Opens the default browser with the URL. 使用URL打开默认浏览器。
Tested on Git Bash/Windows 10. 在Git Bash / Windows 10上测试过。
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
You have few options here: 你在这里几乎没有选择:
chrome "google.com"
. chrome "google.com"
。 For me it is C:\\Program Files (x86)\\Google\\Chrome\\Application
. C:\\Program Files (x86)\\Google\\Chrome\\Application
。 This post explains it. "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" google.com
. "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" google.com
。 Please comment if you need more details. 如果您需要更多详细信息,请评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.