我想做一个像这样的命令:
chrome "site.com"
这将使谷歌浏览器窗口立即弹出该网站。有没有办法实现这个目标?
这对我在Windows 10上使用并使用Git Bash。
start chrome www.google.com
以下是我用来从Git bash(随incognito mode提供)向Google Chrome打开网址或文件到Git for Windows的情况:
sysdm.cpl
并按Enter键。Advanced
1并选择Environmental Variables
2Path
中选择System variables
3并点击Edit
button4。保持此窗口打开(同时获取chrome.exe
文件夹路径)。
chrome.exe
文件夹路径右键单击(如果您的左手是鼠标,则左侧)Chrome icon5(用于打开它的那个)并选择Properties
7。通常此方法会打开更多Chrome操作,因此找到Google Chrome
option6并右键单击它并单击Properties
7。
在Shortcut
8选项卡上,从Start in:
9(通常%programfiles(x86)%\Google\Chrome\Application
)中选择文件夹路径
Environment variables
单击之前打开的New
窗口中的Edit environment variable
button10并将Google Chrome文件夹路径粘贴到新添加的line11中(如果存在于路径的开头或末尾,则删除双引号)并单击打开的窗口中的所有OK
按钮。
打开Git bash终端并使用首选文本编辑器编辑(或创建).bashrc
文件(本例中为Visual Studio代码)
code ~/.bashrc
从下面附加代码。您可以根据需要重命名函数名称(本例中为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
}
如果您不想要隐身模式,请删除--incognito
参数。
非常重要的注意事项:验证您的行结尾是否设置为UNIX(LF)12。如果您不知道该怎么做,请搜索google。
保存.bashrc
文件并重新加载(使用Git bash终端):
source ~/.bashrc
或者您可以使用命令的shorter version:
. ~/.bashrc
关闭Git bash终端窗口或输入exit
并重新打开它。
尝试打开一个网址:
chromeIt google.com
或文件:
chromeIt index.html
我希望这个对你有用。
您可以使用可以在默认浏览器中打开URL的explorer.exe
:
explorer.exe "https://www.google.com/"
因此有一个奇怪的错误:URL不应包含?
,因此:
explorer.exe "https://www.google.com/search?q=foo+bar"
会失败,你需要使用:
explorer.exe "https://www.google.com/search?q=foo+bar&\""
解决。
顺便说一下,我创建了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'
您可以按如下方式使用它:
g site:cppreference.com c++ empty string view
我发现它非常有用,特别是在编码时;)
在Windows上测试Bash(Ubuntu 16.04.3 LTS; GNU bash,版本4.3.48)。
这应该可以解决问题。我无法在Windows 10上测试,但在Ubuntu中使用bash工作正常
google-chrome http://www.google.com
你在这里几乎没有选择:
chrome "google.com"
即可。对我来说这是C:\Program Files (x86)\Google\Chrome\Application
。 This post解释说。"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" google.com
。如果您需要更多详细信息,请评论。