【问题标题】:How do I prefix rails and rake commands with foreman automatically?如何自动为工头添加 rails 和 rake 命令前缀?
【发布时间】:2014-02-04 08:38:45
【问题描述】:

当我在 Rails 项目中时,如何避免打字

foreman run rails console

每次?换句话说,有没有办法自动在railsrake命令前加上foreman run

【问题讨论】:

  • 我假设它在本地开发环境中。为什么不使用 shell 别名?
  • 我有多个 Rails 项目,但它们并不都使用 Heroku。我假设您的意思是我应该将alias rails=foreman run rails 放在我的~/.bash_profile 中,但这范围太广了。理想情况下,别名将仅限于该项目的根目录。
  • 类似的东西,是的。当您“开始处理项目”时,您是否没有运行 shell 脚本,它设置环境变量、路径、更改提示等无论如何?在那里添加别名。
  • 或者只是更改别名,或者创建一个检查它是否使用 Heroku 的函数,然后调用 foreman run rails 或只调用 rails
  • 为了回应 Nitzan,很遗憾我没有这样的脚本。 BroSlow,你能给我举个例子吗?

标签: ruby-on-rails ruby bash heroku foreman


【解决方案1】:

使用 bash 函数:

rails () {
    if test current directory is in a rails project  # left as an exercise
    then
        foreman run rails "$@"
    else
        command rails "$@"
    fi
}

【讨论】:

  • 我将检查项目根目录中是否存在 .env 文件,这应该是 Heroku 的一个公平指示。谢谢。
猜你喜欢
  • 2020-03-18
  • 2015-05-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-16
  • 1970-01-01
相关资源
最近更新 更多