bash 如何从终端打开谷歌浏览器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34796888/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:10:26  来源:igfitidea点击:

How to open google chrome from terminal?

gitbashgoogle-chrometerminalalias

提问by Spencer Rohan

I'm trying to create an alias that opens google chrome to localhost. Port 80 in this case.

我正在尝试创建一个别名,将谷歌浏览器打开到本地主机。在这种情况下,端口 80。

I'd also really like to be able to be in any git directory and have it open that specific project in the browser, but I'm not sure if that's even possible.

我也非常希望能够在任何 git 目录中并让它在浏览器中打开该特定项目,但我不确定这是否可能。

  • How do I open google chrome from the terminal?
  • What alias could I use to open the current git project in the browser?
  • 如何从终端打开谷歌浏览器?
  • 我可以使用什么别名在浏览器中打开当前的 git 项目?

More Details:

更多细节:

  1. My localhost is set to port 80.
  2. I store my git repositories in ~/Sites/ - meaning if I wanted to view any project in the browser it would be found here: http://localhost/FILENAME
  1. 我的本地主机设置为端口 80。
  2. 我将我的 git 存储库存储在 ~/Sites/ 中 - 这意味着如果我想在浏览器中查看任何项目,可以在这里找到它: http://localhost/FILENAME

Thank You

谢谢你

采纳答案by Spencer Rohan

UPDATE:

更新:

  1. How do I open google chrome from the terminal?
  1. 如何从终端打开谷歌浏览器?

Thank you for the quick response. open http://localhost/opened that domain in my default browser on my Mac.

谢谢你的快速反应。open http://localhost/在 Mac 上的默认浏览器中打开该域。

  1. What alias could I use to open the current git project in the browser?
  1. 我可以使用什么别名在浏览器中打开当前的 git 项目?

I ended up writing this alias, did the trick:

我最终写了这个别名,做到了:

# Opens git file's localhost; ${PWD##*/} is the current directory's name
alias lcl='open "http://localhost/${PWD##*/}/"'

Thank you again!

再次感谢你!

回答by John

From the macOS Terminal, use openwith the -aflag and give the name of the app you want to open. In this case "Google Chrome". You may pass it a file or URL you want it to open with.

从MacOS的终端,采用open-a标志,给你想要打开的应用程序的名称。在这种情况下,“谷歌浏览器”。您可以向它传递一个您希望它打开的文件或 URL。

open -a "Google Chrome" index.html 

回答by theRana

If you just want to open the Google Chrome from terminal instantly for once then open -a "Google Chrome"works fine from Mac Terminal.

如果您只想立即从终端打开谷歌浏览器一次,那么 open -a "Google Chrome"从 Mac 终端可以正常工作。

If you want to use an alias to call Chrome from terminal then you need to edit the bash profile and add an alias on ~/.bash_profileor ~/.zshrcfile.The steps are below :

如果您想使用别名从终端调用 Chrome,那么您需要编辑 bash 配置文件并在~/.bash_profile或文件上添加别名。~/.zshrc步骤如下:

  • Edit ~/.bash_profileor ~/.zshrcfile and add the following line alias chrome="open -a 'Google Chrome'"
  • Save and close the file.
  • Logout and relaunch Terminal
  • Type chrome filenamefor opening a local file.
  • Type chrome urlfor opening url.
  • 编辑~/.bash_profile~/.zshrc文件并添加以下行alias chrome="open -a 'Google Chrome'"
  • 保存并关闭文件。
  • 注销并重新启动终端
  • chrome filename用于打开本地文件的类型。
  • 键入chrome url开网址。

回答by Hassan Abbasi

On Linux, just use this command in a terminal:

在 Linux 上,只需在终端中使用此命令:

google-chrome

回答by jamz

I'm not sure how extensively you've searched, but this seems to be similar to what you're searching for:

我不确定您搜索的范围有多广,但这似乎与您要搜索的内容相似:

https://apple.stackexchange.com/questions/83630/create-a-terminal-command-to-open-file-with-chrome

https://apple.stackexchange.com/questions/83630/create-a-terminal-command-to-open-file-with-chrome

(I just assumed you're using Mac since you used the word "terminal")

(我只是假设您使用的是 Mac,因为您使用了“终端”这个词)

回答by DGomonov

In Terminal, type open -a Google\ Chrome

终端中,输入open -a Google\ Chrome

This will open Google Chrome application without any need to manipulate directories!

这将打开 Google Chrome 应用程序,无需操作目录!

回答by Y. Joy Ch. Singha

just type

只需输入

google-chrome

it works. Thanks.

有用。谢谢。

回答by MauiGonzo

on mac terminal (at least in ZSH): open stackoverflow.com(opens site in new tab in your chrome default browser)

在 mac 终端上(至少在 ZSH 中):(open stackoverflow.com在 chrome 默认浏览器的新选项卡中打开站点)