initial commit

This commit is contained in:
THEON-1
2025-12-04 19:12:13 +01:00
commit 5632833dab
5 changed files with 181 additions and 0 deletions

27
battery Executable file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
CHARGING_SYMBOLS=( 󰢟 󰢜 󰂆 󰂇 󰂈 󰢝 󰂉 󰢞 󰂊 󰂋 󰂅 )
DISCHARGING_SYMBOLS=( 󰂎 󰁺 󰁻 󰁼 󰁽 󰁾 󰁿 󰂀 󰂁 󰂂 󰁹 )
PERCENTAGE=$(cat /sys/class/power_supply/BAT0/capacity)
STATUS=$(cat /sys/class/power_supply/ACAD/online)
STATUS_INDEX="$((($PERCENTAGE+5)/10))"
if [ "$STATUS" = "1" ]; then
STATUS_SYMBOL="${CHARGING_SYMBOLS[STATUS_INDEX]}"
else
STATUS_SYMBOL="${DISCHARGING_SYMBOLS[STATUS_INDEX]}"
fi
if [ "$STATUS" = "1" ]; then
COLOR_CODE='#98971a'
elif [ $PERCENTAGE -lt 20 ]; then
COLOR_CODE='#CC241D'
elif [ $PERCENTAGE -lt 50 ]; then
COLOR_CODE='#D79921'
fi
echo "$STATUS_SYMBOL $PERCENTAGE%"
echo "$PERCENTAGE%"
echo "$COLOR_CODE"

46
config Normal file
View File

@@ -0,0 +1,46 @@
# i3blocks configuration file
#
# The i3blocks man page describes the usage of the binary,
# and its website describes the configuration:
#
# https://vivien.github.io/i3blocks
# Global properties
separator=true
separator_block_width=15
[Volume]
command=echo "$(wpctl get-volume @DEFAULT_SINK@ 2>/dev/null | grep -q 'MUTED' && echo '' || echo '') $(wpctl get-volume @DEFAULT_SINK@ 2>/dev/null | grep -Eo ' \S*' | head -n 1)%" | tr -d . | sed "s/ 0/ /g"
interval=10
[Brightness]
command=echo "100*$(brightnessctl g)/$(brightnessctl m)" | bc | sed "s/$/%/g"
label=󰃠
interval=10
[Iface]
command=./iface
color=#98971a
interval=10
[Wifi]
command=./wifi
label=
interface=wlp1s0
interval=10
[Cpu]
command=./cpu_usage
label=
interval=10
[Battery]
command=./battery
interval=30
[Time]
command=date
label=
interval=1

25
cpu_usage Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
USAGE_DATA_1=$(cat /proc/stat | grep "cpu ")
sleep 1
USAGE_DATA_2=$(cat /proc/stat | grep "cpu ")
IFS=" " read -r -a DATA_1 <<< "$USAGE_DATA_1"
IFS=" " read -r -a DATA_2 <<< "$USAGE_DATA_2"
SUM_STR="0"
for i in "${!DATA_1[@]}"; do
if [ "$i" -ne "0" ]; then
SUM_STR="$SUM_STR + ${DATA_2[i]} - ${DATA_1[i]}"
fi
done
SUM=$(echo $SUM_STR | bc)
TIME_IDLE=$(echo "${DATA_2[4]} - ${DATA_1[4]}" | bc)
USAGE=$(echo "100 - (100 * $TIME_IDLE / $SUM)" | bc)
echo "$USAGE%"
echo "$USAGE%"
if [ "$USAGE" -gt "80" ]; then
echo "#CC241D"
fi

61
iface Executable file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------
# Use the provided interface, otherwise the device used for the default route.
if [[ -n $BLOCK_INSTANCE ]]; then
IF=$BLOCK_INSTANCE
else
IF=$(ip route | awk '/^default/ { print $5 ; exit }')
fi
#------------------------------------------------------------------------
# As per #36 -- It is transparent: e.g. if the machine has no battery or wireless
# connection (think desktop), the corresponding block should not be displayed.
[[ ! -d /sys/class/net/${IF} ]] && exit
#------------------------------------------------------------------------
if [[ "$(cat /sys/class/net/$IF/operstate)" = 'down' ]]; then
echo down # full text
echo down # short text
echo \#FF0000 # color
exit
fi
case $1 in
-4)
AF=inet ;;
-6)
AF=inet6 ;;
*)
AF=inet6? ;;
esac
# if no interface is found, use the first device with a global scope
IPADDR=$(ip addr show $IF | perl -n -e "/$AF ([^\/]+).* scope global/ && print \$1 and exit")
case $BLOCK_BUTTON in
3) echo -n "$IPADDR" | xclip -q -se c ;;
esac
#------------------------------------------------------------------------
echo "$IPADDR" # full text
echo "$IPADDR" # short text

22
wifi Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
if [[ ! -d /sys/class/net/${interface}/wireless ]] || [[ "$(cat /sys/class/net/$interface/operstate)" = "down" ]];
then exit
fi
DATA=$(grep $interface /proc/net/wireless)
IFS=" " read -r -a DATA <<< "$DATA"
QUALITY=$(echo "${DATA[2]}*100/70" | bc)
echo "$QUALITY%"
echo "$QUALITY%"
if [[ $QUALITY -ge 80 ]]; then
echo "#98971a"
elif [[ $QUALITY -lt 80 ]]; then
echo "#D79921"
elif [[ $QUALITY -lt 60 ]]; then
echo "#FFAE00"
elif [[ $QUALITY -lt 40 ]]; then
echo "#FF0000"
fi