首页 > 解决方案 > 鱼壳可以处理 if 语句中的 if 语句吗?

问题描述

我试图让我的 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!

这里会发生什么?

标签: fish

解决方案


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

   if contains $TERM acceptable_terms

缺少$第二个变量!

if contains $TERM $acceptable_terms

推荐阅读