用鱼检查流浪状态
Check vagrant status with fish
我正在尝试编写一个 fish 脚本来检查当前的 vagrant 状态并根据它做一些事情。一个简单的例子是:
检查 vagrant 是否 运行,如果是,则执行 vagrant halt,如果不是,则执行 vagrant up。
我想到了类似的东西:
# Go to vagrant folder
cd "/vagrant/folder"
# Set status
set status(vagrant status --machine-readable | grep state,running)
# Check status
if [ status != "" ]
vagrant halt
# Send notification
notify-send "Vagrant is halted."
else
vagrant up
# Send notification
notify-send "Vagrant is up."
end
我不知道字符串比较是否可行,或者是否有更简洁、更精确的方法来检查 vagrant 状态。
通过测试和 $status 找到解决方案
# Get status
vagrant status --machine-readable | grep state,running
# Check status
if test $status -eq 0
# Vagrant is running
vagrant halt
# Send notification
notify-send "Vagrant is halted."
else
# Vagrant is not running
vagrant up
# Send notification
notify-send "Vagrant is up."
end
我正在尝试编写一个 fish 脚本来检查当前的 vagrant 状态并根据它做一些事情。一个简单的例子是:
检查 vagrant 是否 运行,如果是,则执行 vagrant halt,如果不是,则执行 vagrant up。
我想到了类似的东西:
# Go to vagrant folder
cd "/vagrant/folder"
# Set status
set status(vagrant status --machine-readable | grep state,running)
# Check status
if [ status != "" ]
vagrant halt
# Send notification
notify-send "Vagrant is halted."
else
vagrant up
# Send notification
notify-send "Vagrant is up."
end
我不知道字符串比较是否可行,或者是否有更简洁、更精确的方法来检查 vagrant 状态。
通过测试和 $status 找到解决方案
# Get status
vagrant status --machine-readable | grep state,running
# Check status
if test $status -eq 0
# Vagrant is running
vagrant halt
# Send notification
notify-send "Vagrant is halted."
else
# Vagrant is not running
vagrant up
# Send notification
notify-send "Vagrant is up."
end