【问题标题】:Aliasing Chrome in terminal with a http:// prefix使用 http:// 前缀在终端中为 Chrome 起别名
【发布时间】:2020-08-17 15:27:23
【问题描述】:

我正在尝试向终端添加一个别名,允许我说“chrome github.com”并打开我在 chrome 中提供的 url。

我想将 http:// 添加到别名中,这样我就可以在前面键入不带 http:// 的 URL。

这是我现在得到的:

别名 chrome="open -a \"Google Chrome\" http://"

目前,如果我只是调用 Chrome,则会打开一个新标签页并使用 url(减去 http://)调用它会返回:

文件 /Users/name/github.com 不存在。

【问题讨论】:

  • open -a "Google Chrome" http://github.com 是否在终端上工作?因为你使用open,你是在 MacOS 上吗?请将操作系统添加到标签中。
  • @KamilCuk 是的,我在 MacOS 上,我也将它添加到标签中。运行 open -a "Google Chrome" github.com 确实可以从终端运行,是的。

标签: bash macos terminal scripting alias


【解决方案1】:

只需使用一个函数,它的作用类似于别名,更加灵活和可读。

chrome() {
       open -a "Google Chrome" http://"$@"
}

alias 在调用后添加一个空格。所以你的别名chrome github.comopen -a "Google Chrome" http:// github.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-10
    • 2018-08-20
    • 2019-10-05
    • 2019-08-27
    • 2020-10-22
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    相关资源
    最近更新 更多