比较鱼中的命令替换字符串不为空

问题描述

我正在尝试测试 git 存储库是否将 uwsgi.ini 选项设置为 showuntrackedfiles

我的第一次访问是:

no

但是如果 if test (git config --get status.showuntrackedfiles) = no echo "hi" else echo "bye" end 没有设置,这会中断。

showuntrackedfiles

我发现的唯一解决方法是:

test: Missing argument at index 2

(Type 'help test' for related documentation)
bye

但它看起来很hacky。有没有更好的方法解决这个问题?

解决方法

同样是 hacky,但这里有一种方法可以查看命令替换是否没有返回任何内容:

set output (git config ...)
if test (count $output) -gt 0 -a $output = no; ...

回想一下 fish 变量是列表,因此 count 正在检查列表是否包含多于零个元素。