在Fish Shell中使用anyenv

时间:2017-02-08 14:47:36

标签: shell fish

我尝试在Fish Shell中使用anyenv,但发生了错误。

这是我的~./config/fish/config.fish文件。

set -x PATH $HOME/.anyenv/bin $PATH
eval (anyenv init -)

这有什么问题?

我得到的错误:

$# is not supported. In fish, please use 'count $argv'.
- (line 1): begin; source "/Users/kasumi/.anyenv/libexec/../completions/anyenv.bash" anyenv() {   typeset command   command="$1"   if [ "$#" -gt 0 ]; then     shift   fi   command anyenv "$command" "$@" } export NDENV_ROOT="/Users/kasumi/.anyenv/envs/ndenv" export PATH="/Users/kasumi/.anyenv/envs/ndenv/bin:$PATH" export PATH="/Users/kasumi/.anyenv/envs/ndenv/shims:${PATH}" source "/Users/kasumi/.anyenv/envs/ndenv/libexec/../completions/ndenv.bash" ndenv rehash 2>/dev/null ndenv() {   typeset command   command="$1"   if [ "$#" -gt 0 ]; then     shift   fi    case "$command" in   rehash|shell)     eval "`ndenv "sh-$command" "$@"`";;   *)     command ndenv "$command" "$@";;   esac }
                                                                                                                                      ^
from sourcing file -
    called on line 60 of file /usr/local/Cellar/fish/2.4.0/share/fish/functions/eval.fish

in function 'eval'
    called on line 6 of file ~/.config/fish/config.fish

from sourcing file ~/.config/fish/config.fish
    called on standard input

source: Error while reading file '-'

加了:

我尝试了回答(https://stackoverflow.com/a/42119354/7524270)但我收到了一些新错误。

新错误:

Variables cannot be bracketed. In fish, please use "$PATH".
- (line 1): begin; source     "/Users/kasumi/.anyenv/libexec/../completions/anyenv.fish" function anyenv   set command $argv[1]   set -e argv[1]    command anyenv "$command" $argv end set -x NDENV_ROOT "/Users/kasumi/.anyenv/envs/ndenv" set -x PATH $PATH "/Users/kasumi/.anyenv/envs/ndenv/bin" export PATH="/Users/kasumi/.anyenv/envs/ndenv/shims:${PATH}" ndenv rehash 2>/dev/null ndenv() {   typeset command   command="$1"   if [ "$#" -gt 0 ]; then     shift   fi    case "$command" in   rehash|shell)     eval "`ndenv "sh-$command" "$@"`";;   *)     command ndenv "$command" "$@";;   esac } 
                                                                                                                                                                                                                                                                                                                                                   ^
from sourcing file -
called on line 60 of file /usr/local/Cellar/fish/2.5.0/share/fish/functions/eval.fish

in function 'eval'
called on line 4 of file ~/.config/fish/config.fish

from sourcing file ~/.config/fish/config.fish
called during startup

source: Error while reading file '-'

1 个答案:

答案 0 :(得分:2)

快速修复:

〜/ .config / fish / config.fish 中,更改:

eval (anyenv init -)

为:

eval (anyenv init - fish)

编辑: 或稍微更防弹的方法:

eval (command anyenv init - fish)

command强制fish忽略函数)


发生了什么事?

anyenv init使用$SHELL环境变量来确定您的活动shell并返回一些命令,由shell执行,以完成anyenv的初始化。

由于某些原因,您环境中的$SHELL变量指向bash而不是fish(您可以通过运行echo $SHELL来验证这一点。)

最可能的原因是fish根本不是您用户的默认shell。您可以执行grep $USER /etc/passwd查找(查看上一次:之后的内容)。可以使用chsh更改默认shell,但如果您决定这样做,请务必小心谨慎。您的.bashrc或其他一些程序中可能有一些重要设置可能依赖于符合POSIX标准的shell来正常工作。

另一个选择是,您可以覆盖$SHELL变量,使其指向bash而不是fish。我在我的byobu / tmux配置中有这个,因为它帮助我避免了一些奇怪的行为。

幸运的是,anyenv init允许用户(您)手动指定shell(忽略$SHELL),这应该可以解决anyenv的问题。