bash变色效果?

时间:2017-06-07 17:15:16

标签: bash

我是bash脚本的新手,我正在编写一个脚本来显示i3blocks中的电池状态。我有一个小闪电标志符号表示电池正在充电。我想拥有它,所以颜色在绿色和另一种颜色之间切换。下面的代码在充电时输出绿色螺栓字形,只是粘在如何使其交替颜色。

#! /bin/bash
bat=$(upower -i /org/freedesktop/UPower/devices/battery_BAT1 | grep 
percentage | cut -c26-)
bat=$(echo "${bat//%}")
ac=$(acpi -a | cut -c12-)
warning="<span color='orange'><span font='FontAwesome'></span></span>"
red="<span color='red'><span font='FontAwesome'> Charge!</span></span>"
charged="<span color='green'><span font='Monaco'>Charged!</span></span>"
bolt="<span color='green'><span font='FontAwesome'></span></span>"
boltz="<span color='black'><span font='FontAwesome'></span></span>"

if [ "$ac" == on-line ] && [ "$bat" -le 94 ]; then
  echo " $bolt" #this is where i want the color to switch
elif [ "$ac" == on-line ] && [ "$bat" -ge 95 ]; then
  echo "Charged"

else
  if [ "$bat" -ge 95 ]; then
    echo ""
  elif [ "$bat" -ge 70 ]; then
    echo ""
  elif [ "$bat" -ge 50 ]; then
    echo ""
  elif [ "$bat" -ge 30 ]; then
    echo "$warning"
  elif [ "$bat" -ge 10 ]; then
    echo "$red"
  fi
fi

0 个答案:

没有答案