我正在尝试编写一个简短的函数,以允许我从命令行打开和关闭wemo指示灯。基本上,我有一个命令,如果我输入的内容wemo status
将Switch: Lights 1
在灯打开时返回,或者在灯熄灭时返回0。我想编写一个fish函数,从本质上讲,我可以切换它们:
function lights --description 'Toggle lights'
if contains (wemo status) "Lights 1"
wemo switch "Lights" off
else
wemo switch "Lights" on
end
end
虽然这不起作用。我认为原谅可能是文字替换?有谁知道我可以如何测试一个字符串是否在Fish中包含另一个字符串?
所以我最终用以下方法解决了这个问题:
# Toggle lights
function lights --description "Toggle Wemo Lights"
set -l wemo (wemo status)
switch $wemo
case '*1'
wemo switch "Lights" off
case '*0'
wemo switch "Lights" on
end
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句