33695
昨日からfishシェルを使い始めまして、anyenvの設定を `~/.config/fish/config.fish` に記述しました。

```

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

そしてfishを起動すると、以下のエラーがでました。

```

    Variables cannot be bracketed. In fish, please use "$PATH".
    - (line 1): begin; source "/home/vagrant/.anyenv/libexec/../completions/anyenv.fish" function anyenv   set command $argv[1]   set -e argv[1]    command anyenv "$command" $argv end set -x GOENV_ROOT "/home/vagrant/.anyenv/envs/goenv" set -x PATH $PATH "/home/vagrant/.anyenv/envs/goenv/bin" export PATH="/home/vagrant/.anyenv/envs/goenv/shims:${PATH}" goenv rehash 2>/dev/null set -x NDENV_ROOT "/home/vagrant/.anyenv/envs/ndenv" set -x PATH $PATH "/home/vagrant/.anyenv/envs/ndenv/bin" 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 } set -x PYENV_ROOT "/home/vagrant/.anyenv/envs/pyenv" set -x PATH $PATH "/home/vagrant/.anyenv/envs/pyenv/bin" setenv PATH '/home/vagrant/.anyenv/envs/pyenv/shims' $PATH setenv PYENV_SHELL fish . '/home/vagrant/.anyenv/envs/pyenv/libexec/../completions/pyenv.fish' command pyenv rehash 2>/dev/null function pyenv   set command $argv[1]   set -e argv[1]    switch "$command"   case rehash shell     . (pyenv "sh-$command" $argv|psub)   case '*'     command pyenv "$command" $argv   end end set -x RBENV_ROOT "/home/vagrant/.anyenv/envs/rbenv" set -x PATH $PATH "/home/vagrant/.anyenv/envs/rbenv/bin" setenv PATH '/home/vagrant/.anyenv/envs/rbenv/shims' $PATH setenv RBENV_SHELL fish source '/home/vagrant/.anyenv/envs/rbenv/libexec/../completions/rbenv.fish' command rbenv rehash 2>/dev/null function rbenv   set command $argv[1]   set -e argv[1]    switch "$command"   case rehash shell     source (rbenv "sh-$command" $argv|psub)   case '*'     command rbenv "$command" $argv   end end
                                                                                                                                                                                                                                                                                                                                                           ^
    from sourcing file -
            called on line 60 of file /usr/local/share/fish/functions/eval.fish
    
    in function “eval”
            called on line 15 of file ~/.config/fish/config.fish
    
    from sourcing file ~/.config/fish/config.fish
            called during startup
    
    source: Error while reading file “-”
    
```

エラー内容をググってもどうにもならなかったので、config.fishの`eval`部分を`anenv init -
fish`で表示される内容に変えてみました。

```

    set -x PATH $HOME/.anyenv/bin $PATH
    
    # anyenv init - fish で出てくる内容
    source "/home/vagrant/.anyenv/libexec/../completions/anyenv.fish"
    function anyenv
      set command $argv[1]
      set -e argv[1]
    
      command anyenv "$command" $argv
    end
    
    set -x GOENV_ROOT "/home/vagrant/.anyenv/envs/goenv"
    set -x PATH $PATH "/home/vagrant/.anyenv/envs/goenv/bin"
    export PATH="/home/vagrant/.anyenv/envs/goenv/shims:${PATH}"
    goenv rehash 2>/dev/null
    set -x NDENV_ROOT "/home/vagrant/.anyenv/envs/ndenv"
    set -x PATH $PATH "/home/vagrant/.anyenv/envs/ndenv/bin"
    export PATH="/home/vagrant/.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
    }
    
    set -x PYENV_ROOT "/home/vagrant/.anyenv/envs/pyenv"
    set -x PATH $PATH "/home/vagrant/.anyenv/envs/pyenv/bin"
    setenv PATH '/home/vagrant/.anyenv/envs/pyenv/shims' $PATH
    setenv PYENV_SHELL fish
    . '/home/vagrant/.anyenv/envs/pyenv/libexec/../completions/pyenv.fish'
    command pyenv rehash 2>/dev/null
    
    function pyenv
      set command $argv[1]
      set -e argv[1]
    
      switch "$command"
      case rehash shell
        . (pyenv "sh-$command" $argv|psub)
      case '*'
        command pyenv "$command" $argv
      end
    end
    
    set -x RBENV_ROOT "/home/vagrant/.anyenv/envs/rbenv"
    set -x PATH $PATH "/home/vagrant/.anyenv/envs/rbenv/bin"
    setenv PATH '/home/vagrant/.anyenv/envs/rbenv/shims' $PATH
    setenv RBENV_SHELL fish
    source '/home/vagrant/.anyenv/envs/rbenv/libexec/../completions/rbenv.fish'
    command rbenv rehash 2>/dev/null
    function rbenv
      set command $argv[1]
      set -e argv[1]
    
      switch "$command"
      case rehash shell
        source (rbenv "sh-$command" $argv|psub)
      case '*'
        command rbenv "$command" $argv
      end
    end
    
```

こうしてfishを起動しても、また以下のエラーが出ます。どのように対応すれば良いのでしょうか？

```

    'case' builtin not inside of switch block
    ~/.config/fish/config.fish (line 43):   case "$command" in
                                            ^
    from sourcing file ~/.config/fish/config.fish
            called during startup
    
    source: Error while reading file “/home/vagrant/.config/fish/config.fish”
    
```

ちなみにanyenvは最新バージョンにアップデートしてあります。  
よろしくお願い致します。
CC BY-SA 3.0
2017-04-01T13:49:19.103
33694
2017-04-01T15:32:05.393
11178
question
shell
fishシェルでanyenvを設定したときにcalled during startupエラーが出る
バグといいますか、コードを見る限り、`goenv` や `ndenv` は `fish` に対応していないです。  
想定しているのは`bash`、`ksh`、`zsh`です。  
<https://github.com/kaneshin/goenv/blob/master/libexec/goenv-init#L56>  
<https://github.com/riywo/ndenv/blob/master/libexec/ndenv-init#L59>

`pyenv` と `rbenv`は対応しているようです。  
<https://github.com/pyenv/pyenv/blob/master/libexec/pyenv-init#L46>  
<https://github.com/rbenv/rbenv/blob/master/libexec/rbenv-init#L35>

metropolis さんがコメントで指摘している`${PATH}`の件も、

> 'case' builtin not inside of switch block

というエラーも、sh系の文法を `fish` に読ませた事が原因です。

* * *

解決策としては二つ、

  * 自分で頑張って対応させる
  * `bash` などで環境のスイッチをした後に `fish` を起動する

が考えられます。
CC BY-SA 3.0
2017-04-01T14:23:50.620
33695
2017-04-01T15:32:05.393
2017-04-01T15:32:05.393
3054
3054
33694
answer