Difference between revisions of "Openbsd-statusbar-snippets"

From Personal Knowledgebase
(Created page with "= Dzen2 Snippets = <pre> #!/bin/sh sleep 2 # Get screen width SCRN_WIDTH=`xrandr --prop | grep "^Screen 0" | cut -d, -f2 | awk '{print $2}'` #HALF_SCRN=`dc -e "$SCRN_WIDTH...")
(No difference)

Revision as of 23:32, 26 July 2020

Dzen2 Snippets

#!/bin/sh

sleep 2

# Get screen width
SCRN_WIDTH=`xrandr --prop | grep "^Screen 0" | cut -d, -f2 | awk '{print $2}'`
#HALF_SCRN=`dc -e "$SCRN_WIDTH 2 / p"`
DZEN_WIDTH=740

# Settings
BG='#222222'  # background
FG='#cccccc'  # foreground
FN='fixed' # font
XX=`dc -e "$SCRN_WIDTH $DZEN_WIDTH - p"`
YY=0
WDTH=$DZEN_WIDTH
 
DZEN="dzen2 -ta r -fg $FG -bg $BG -fn $FN -h 14 -x $XX -y $YY -w $WDTH"

PICCPU="^i($HOME/.dzen/bitmaps/1/cpu.xbm)" 
PICTEMP="^i($HOME/.dzen/bitmaps/1/temp.xbm)" 
PICMEM="^i($HOME/.dzen/bitmaps/1/mem.xbm)" 
PICAC="^i($HOME/.dzen/bitmaps/1/power-ac.xbm)"
PICBAT="^i($HOME/.dzen/bitmaps/1/power-bat2.xbm)"
PICUP="^fg(orange3)^i($HOME/.dzen/bitmaps/1/up.xbm)^fg()"
PICDOWN="^fg(#80AA83)^i($HOME/.dzen/bitmaps/1/down.xbm)^fg()"
PICNETWIRED="^i($HOME/.dzen/bitmaps/1/net-wired2.xbm)"
PICNETWIFI="^i($HOME/.dzen/bitmaps/1/net-wifi.xbm)"
PICNET="^i($HOME/.dzen/bitmaps/1/net-wired.xbm)"
#DOT="^p(5)^c(5)^p(5)"
DOT="^c(5)^p(5)"
 
while true; do
sleep .5

eval `vmstat -c 2 | awk 'NR > 3 {print "FREEMEM="$5*1024 "\nCPU_U="$17 "\nCPU_S="$18 "\nCPU_I="$19}'`

# CPU
CPU_USAGE=`echo "100-$CPU_I" | bc`"%"
CPU_SPD=`sysctl -n hw.cpuspeed`
CPU_SPEED=`echo "$CPU_SPD/1000" | bc`"GHz"
CPU_TEMP=`sysctl -n hw.sensors.cpu0.temp0 | cut -d. -f1`"C"

# Memory
TOTALMEM=`sysctl -n hw.physmem` 
USEDMEM=`echo "($TOTALMEM-$FREEMEM)*100/$TOTALMEM" | bc`"%"

# Battery and AC 
eval `sysctl -n \
  hw.sensors.acpibat0.watthour0 \
  hw.sensors.acpibat0.watthour1 \
  hw.sensors.acpibat0.watthour3 \
  hw.sensors.acpibat0.raw0 \
  hw.sensors.acpiac0.indicator0 \
  | awk '{print "SYSCTL" NR "=" $1}' `

if [ -z $SYSCTL5 ]; then
  AC_BOOL=${SYSCTL1}
  BAT="No"
else
        BAT="Yes"
  BAT_FULL=${SYSCTL1}
        BAT_WARN=${SYSCTL2}
  BAT_CURRENT=${SYSCTL3}
  BAT_STATE=${SYSCTL4} 
  BAT_PERC=`echo "100 * ${BAT_CURRENT} / ${BAT_FULL}" | bc`
  AC_BOOL=${SYSCTL5}
fi

if  [[ ${AC_BOOL} = "On" ]]; then
        if [[ ${BAT} = "No" ]]; then
                POWER="$PICAC"
        else
                if [[ ${BAT_STATE} = 0 ]]; then
                  POWER="^fg(#80AA83)$PICBAT ${BAT_PERC}% ^fg()"
                elif [[ ${BAT_STATE} = 2 ]]; then
                  POWER="^fg(#8083AA)$PICBAT ${BAT_PERC}% ^fg()"
                fi
        fi
else
        if [[ ${BAT_CURRENT} -lt ${BAT_WARN} ]]; then
          POWER="^fg(red)$PICBAT ${BAT_PERC}%^fg()"
        else
          POWER="^fg(orange3)$PICBAT ${BAT_PERC}%^fg()"
        fi
fi

# Network
#eval `ifstat -i em0,urtwn0 0.1 1 | awk '/[^a-z][0-9\.]+/ {print "EM0DOWN=" $1 "; EM0UP=" $2 "; WPI0DOWN=" $3 "; WPI0UP=" $4}'`
eval `ifstat -T 0.1 1 | awk '/[^a-z][0-9\.]+/ {print "TDOWN=" $(NF-1) "; TUP=" $NF}'`
 
EM0TRAF="${EM0DOWN}kB/s${PICDOWN} ${EM0UP}kB/s${PICUP}"
WPI0TRAF="${WPI0DOWN}kB/s${PICDOWN} ${WPI0UP}kB/s${PICUP}"
TOTTRAF="${TDOWN}kB/s${PICDOWN} ${TUP}kB/s${PICUP}"
 
# Clock
CLOCK=`date +"%d.%m.%Y %k:%M"`
 
#echo "$PICCPU $CPU_USAGE "@" $CPU_SPEED $PICTEMP $CPU_TEMP $DOT $PICMEM $USEDMEM $DOT $PICNETWIRED $EM0TRAF $PICNETWIFI $WPI0TRAF $DOT $POWER $DOT $CLOCK"
echo "$PICCPU $CPU_USAGE "@" $CPU_SPEED $PICTEMP $CPU_TEMP $DOT $PICMEM $USEDMEM $DOT $PICNET $TOTTRAF $DOT $POWER $DOT $CLOCK"
done | $DZEN