如何从终端打开谷歌铬?

我试图创建一个别名,打开谷歌铬本地主机。端口80在这种情况下。

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

  • 如何从终端打开谷歌浏览器?
  • 我可以使用什么别名在浏览器中打开当前的 git 项目?

更多详情:

  1. 我的本地主机设置为端口80。
  2. 我将 git 存储库存储在 ~/Sites/中——这意味着如果我想在浏览器中查看任何项目,都可以在这里找到: http://localhost/FILENAME

谢谢你

186857 次浏览

UPDATE:

  1. How do I open google chrome from the terminal?

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

  1. What alias could I use to open the current git project in the browser?

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!

From the macOS Terminal, use open with the -a flag 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.

open -a "Google Chrome" index.html

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

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_profile or ~/.zshrc file.The steps are below :

  • Edit ~/.bash_profile or ~/.zshrc file and add the following line alias chrome="open -a 'Google Chrome'"
  • Save and close the file.
  • Logout and relaunch Terminal
  • Type chrome filename for opening a local file.
  • Type chrome url for opening url.

On Linux, just use this command in a terminal:

google-chrome

In Terminal, type open -a Google\ Chrome

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

just type

google-chrome

it works. Thanks.

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

Use command

google-chrome-stable

We can also use command

google-chrome

To open terminal but in my case when I make an interrupt ctrl + c then it get closed so I would recommend to use google-chrome-stable instead of google-chrome

On linux [ubuntu] in terminal, write:

google-chrome 'https://google.com' 2> /dev/null

ending part 2> /dev/null ommits output from command in terminal and allows to type without disturbing comments from that command.

for new-ones in scripting (linux users):
u can also create some nice readable function in ~/.bashrc directory like:

open(){
google-chrome $1 2> /dev/null
}

and in terminal using it like this:

open htts://google.com

For macOS you can use this command:

open -a Google\ Chrome "https://google.com"

For Windows:

start chrome "https://www.google.com"