鱼壳可以在if语句中处理if语句吗?

时间:2018-08-24 15:30:30

标签: fish

我正在尝试使config.fish正常工作,但是它没有按预期工作,我真的不明白为什么。我能做的最好的就是猜测,如果Fish不能在if语句中使用if语句,那可能是鱼?这是我的代码:

echo "so far so good"
if status --is-interactive
    # Chips: fish plugin manager
    if [ -e ~/.config/chips/build.fish ] ; . ~/.config/chips/build.fish ; end

    echo "def interactive"
    # Don't use vi keybindings in unknown terminals,
    # since weird things can happen.
    set acceptable_terms xterm-256color screen-256color xterm-termite
    echo "acceptable terms: $acceptable_terms"
    echo "term: $TERM"
    if contains $TERM acceptable_terms
        echo "good to go!"
        fish_vi_key_bindings
        # Load pywal colors
        cat ~/.cache/wal/sequences
    else
       echo "why?!?!?"
    end
end

我得到的是这个:

so far so good
def interactive
acceptable terms: xterm-256color screen-256color xterm-termite
term: xterm-termite
why?!?!?

但是我希望看到的是:

so far so good
def interactive
acceptable terms: xterm-256color screen-256color xterm-termite
term: xterm-termite
good to go!

但是当我在shell中运行它时,如果工作正常:

❯ echo "term: $TERM / acceptable: $acceptable_terms"                
term: xterm-termite / acceptable: xterm-256color screen-256color xterm-termite
❯ if contains $TERM $acceptable_terms                               
    echo "yay!"
  end
yay!

这可能是怎么回事?

1 个答案:

答案 0 :(得分:4)

当然,鱼可以处理嵌套的if语句!

   if contains $TERM acceptable_terms

在第二个变量上缺少$

if contains $TERM $acceptable_terms