将本地 binstubs 添加到 rbenv (getting command not found)

Add local binstubs to rbenv (getting command not found)

如果您在 Rails 项目的本地 bin 目录中有简单的 shell 命令 binstub(例如,不是由 运行 生成或 gem), rbenv 似乎无法执行它们。比如@tpope的heroku binstubs在本地bin目录下生成一个名为production的binstub:

#!/bin/sh
HEROKU_APP=myapp-production HKAPP=myapp-production exec "${HEROKU_COMMAND:-heroku}" "$@"

rbenv 重新哈希后,生产命令显示在 ~/.rbenv/shims 目录中,如下所示:

#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x

program="${0##*/}"
if [ "$program" = "ruby" ]; then
  for arg; do
    case "$arg" in
    -e* | -- ) break ;;
    */* )
      if [ -f "$arg" ]; then
        export RBENV_DIR="${arg%/*}"
        break
      fi
      ;;
    esac
  done
fi

export RBENV_ROOT="/Users/Username/.rbenv"
exec "/usr/local/Cellar/rbenv/0.4.0/libexec/rbenv" exec "$program" "$@"

所以执行 which production 会得到:

/Users/Username/.rbenv/shims/production

但是执行 rbenv which production(或尝试 运行 命令)会得到:

rbenv: production: command not found

我是 rbenv 的新手,所以我可能错过了配置步骤?

显然 Rails 项目中特定于项目的 binstub 应该保存在本地 bin/ 目录之外,因为它们主要用于 application scripts. So one approach (i.e. that used by the rbenv-binstubs 插件)是为了保持本地 binstub 独立并覆盖rbenv 与本地 binstub 目录(例如 .bundle/bin)填充。因此,通过使用该插件,您可能会看到来自 which production:

的结果
/Users/Username/.rbenv/shims/production

但是如果您将 production binstub 移动到 .bundle/bin,那么 rbenv which production 应该会产生:

{PROJECT_ROOT}/.bundle/bin/production