fish shell 可以处理 if 语句中的 if 语句吗?
Can fish shell handle if statements within if statements?
我正在尝试让我的 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 当然可以处理嵌套的 if 语句!
if contains $TERM acceptable_terms
在第二个变量上缺少 $
!
if contains $TERM $acceptable_terms
我正在尝试让我的 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 当然可以处理嵌套的 if 语句!
if contains $TERM acceptable_terms
在第二个变量上缺少 $
!
if contains $TERM $acceptable_terms