Skip to content

Instantly share code, notes, and snippets.

@Jomik
Last active April 5, 2019 08:19
Show Gist options
  • Save Jomik/1fcf55e4e64bb283f7a6563f67a91844 to your computer and use it in GitHub Desktop.
Save Jomik/1fcf55e4e64bb283f7a6563f67a91844 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
function bar {
percent=$1
width=${BAR_WIDTH:-10}
echo -en "<span font='${LABEL_SIZE:-22}'>$LABEL</span> "
echo -n "<span rise='5000'>"
end=$(($width - 1))
for i in $(seq 0 $end); do
segment=$(($i * (100 / $width)))
if (( percent > segment )); then
filled+=${BAR_FILL:-━}
else
empty+=${BAR_EMPTY:-┉}
fi
done
if [ -z $BAR_FILL_COLOR ]; then
echo -en "$filled"
else
echo -en "<span color='$BAR_FILL_COLOR'>$filled</span>"
fi
if [ -z $BAR_EMPTY_COLOR ]; then
echo -en "$empty"
else
echo -en "<span color='$BAR_EMPTY_COLOR'>$empty</span>"
fi
echo "</span>"
}
percent=$(cat /sys/class/power_supply/${BLOCK_INSTANCE:-BAT0}/capacity)
status=$(cat /sys/class/power_supply/${BLOCK_INSTANCE:-BAT0}/status)
if [ $status == "Charging" ] || [ $status == "Full" ]; then
export BAR_FILL_COLOR=$CHARGING
elif ((percent < 30)); then
export BAR_FILL_COLOR=$BAR_CRITICAL_COLOR
fi
bar $percent
#!/usr/bin/env bash
status=$(cat /sys/class/power_supply/${BLOCK_INSTANCE:-BAT0}/status)
if [ $status == "Discharging" ]; then
echo -en "$LABEL"
echo $(cat /sys/class/power_supply/BAT0/{current,voltage}_now | awk -v v=1 '{v*=$0}END{printf "%4.1f W", v*10^-12}')
fi
#!/usr/bin/env bash
function bar {
percent=$1
width=${BAR_WIDTH:-10}
echo -en "<span font='${LABEL_SIZE:-22}'>$LABEL</span> "
echo -n "<span rise='5000'>"
end=$(($width - 1))
for i in $(seq 0 $end); do
segment=$(($i * (100 / $width)))
if (( percent > segment )); then
filled+=${BAR_FILL:-━}
else
empty+=${BAR_EMPTY:-┉}
fi
done
if [ -z $BAR_FILL_COLOR ]; then
echo -en "$filled"
else
echo -en "<span color='$BAR_FILL_COLOR'>$filled</span>"
fi
if [ -z $BAR_EMPTY_COLOR ]; then
echo -en "$empty"
else
echo -en "<span color='$BAR_EMPTY_COLOR'>$empty</span>"
fi
echo "</span>"
}
interface=${BLOCK_INSTANCE:-Master}
case $BLOCK_BUTTON in
4) /nix/store/mlnm53yphbvh037aranj1sy9985h7c28-acpilight-1.1/bin/xbacklight -dec 10 ;;
5) /nix/store/mlnm53yphbvh037aranj1sy9985h7c28-acpilight-1.1/bin/xbacklight -inc 10 ;;
esac
dir=/sys/class/backlight/${BLOCK_INSTANCE:-intel_backlight}
percent=$(( $(cat $dir/brightness) * 100 / $(cat $dir/max_brightness) ))
bar $percent
BAR_EMPTY_COLOR=#928374
BAR_CRITICAL_COLOR=#fb4934
[cpu]
BAR_WIDTH=20
LABEL=\uf85a
command=/nix/store/kk8bk5gkalpdv1hr5yyf99x5rzv0n9z3-cpu
interval=persist
markup=pango
[memory]
LABEL=\uf2db
command=/nix/store/xxvzz1wsz82aif3snrz2yd8qafyin277-memory
interval=1
markup=pango
[volume]
BAR_MUTE_COLOR=#fb4934
LABEL=\ufa7d
command=/nix/store/n9qijd7cqjirvvnf1g4fhqmx6jx464wh-volume
interval=once
markup=pango
signal=11
[brightness]
LABEL=\uf5df
command=/nix/store/iazh81dir1mghiblhzp15f6ifb4lz22b-brightness
interval=once
markup=pango
signal=11
[battery]
CHARGING=#b8bb26
LABEL=\uf240
command=/nix/store/fbhv5zs9xn9x0nhb048vdvmz0g7308m3-battery
interval=30
markup=pango
[battery_draw]
LABEL=\uf0e7
command=/nix/store/yzzb9pm3gm63mqmhapwpnjm0m8ab2khi-battery_draw
interval=1
[ssid]
LABEL=\uf1eb
NOT_CONNECTED_COLOR=#fb4934
command=/nix/store/vad6w2l40fx5nbiafgh93ncyv3z6wngq-ssid
interval=30
markup=pango
[time]
command=date '+%A, %d. %B %H:%M:%S '
interval=1
#!/usr/bin/env bash
function bar {
percent=$1
width=$((${BAR_WIDTH:-10} / 4))
echo -n "<span rise='5000'>"
end=$(($width - 1))
for i in $(seq 0 $end); do
segment=$(($i * (100 / $width)))
if (( percent > segment )); then
filled+=${BAR_FILL:-━}
else
empty+=${BAR_EMPTY:-┉}
fi
done
if [ -z $BAR_FILL_COLOR ]; then
echo -en "$filled"
else
echo -en "<span color='$BAR_FILL_COLOR'>$filled</span>"
fi
if [ -z $BAR_EMPTY_COLOR ]; then
echo -en "$empty"
else
echo -en "<span color='$BAR_EMPTY_COLOR'>$empty</span>"
fi
echo "</span>"
}
for i in $(seq 0 3); do
prev[$i]=$(grep "cpu$i " /proc/stat)
done
while true; do
msg="<span font='${LABEL_SIZE:-22}'>$LABEL</span>"
for i in $(seq 0 3); do
info=$(grep "cpu$i " /proc/stat)
percent=$(echo -e "$prev[$i]\\n$info" | awk -v RS="" '{print ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}' | cut -d "." -f 1)
if (( percent > 70 )); then
export BAR_FILL_COLOR=$BAR_CRITICAL_COLOR
else
export BAR_FILL_COLOR=
fi
msg+=" $(bar $percent)"
$prev[$i]=$info
done
echo -e $msg
sleep ${INTERVAL:-1}
done
#!/usr/bin/env bash
function bar {
percent=$1
width=${BAR_WIDTH:-10}
echo -en "<span font='${LABEL_SIZE:-22}'>$LABEL</span> "
echo -n "<span rise='5000'>"
end=$(($width - 1))
for i in $(seq 0 $end); do
segment=$(($i * (100 / $width)))
if (( percent > segment )); then
filled+=${BAR_FILL:-━}
else
empty+=${BAR_EMPTY:-┉}
fi
done
if [ -z $BAR_FILL_COLOR ]; then
echo -en "$filled"
else
echo -en "<span color='$BAR_FILL_COLOR'>$filled</span>"
fi
if [ -z $BAR_EMPTY_COLOR ]; then
echo -en "$empty"
else
echo -en "<span color='$BAR_EMPTY_COLOR'>$empty</span>"
fi
echo "</span>"
}
percent=$(free | rg "Mem" | awk '{print int($3/$2 * 100)}')
if ((percent > 60)); then
export BAR_FILL_COLOR=$BAR_CRITICAL_COLOR
fi
bar $percent
#!/usr/bin/env bash
echo -en "<span font='22'>$LABEL</span> <span rise='5000'>"
ssid=$(nmcli -t connection show --active | grep ${BLOCK_INSTANCE:-wlp2s0})
if [ $? == 0 ]; then
echo -n "$(echo "$ssid" | cut -d ":" -f 1)"
elif [ -z $NOT_CONNECTED_COLOR ]; then
echo -n "Not connected"
else
echo -n "<span color='$NOT_CONNECTED_COLOR'>Not connected</span>"
fi
echo "</span>"
#!/usr/bin/env bash
function bar {
percent=$1
width=${BAR_WIDTH:-10}
echo -en "<span font='${LABEL_SIZE:-22}'>$LABEL</span> "
echo -n "<span rise='5000'>"
end=$(($width - 1))
for i in $(seq 0 $end); do
segment=$(($i * (100 / $width)))
if (( percent > segment )); then
filled+=${BAR_FILL:-━}
else
empty+=${BAR_EMPTY:-┉}
fi
done
if [ -z $BAR_FILL_COLOR ]; then
echo -en "$filled"
else
echo -en "<span color='$BAR_FILL_COLOR'>$filled</span>"
fi
if [ -z $BAR_EMPTY_COLOR ]; then
echo -en "$empty"
else
echo -en "<span color='$BAR_EMPTY_COLOR'>$empty</span>"
fi
echo "</span>"
}
interface=${BLOCK_INSTANCE:-Master}
case $BLOCK_BUTTON in
1) amixer -q set $interface toggle ;;
4) amixer -q set $interface 5%- unmute ;;
5) amixer -q set $interface 5%+ unmute ;;
esac
info=$(amixer get ${interface:-Master})
percent=$(echo $info | grep "Left" | awk -F "[][]" '/%/ {gsub ("%", ""); print $2 }')
if echo $info | grep "off"; then
export BAR_FILL_COLOR=$BAR_MUTE_COLOR
export BAR_EMPTY_COLOR=$BAR_MUTE_COLOR
fi
bar $percent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment