commit 5632833dab409a97b98b65903e3aa1b2c4d5cc8b Author: THEON-1 Date: Thu Dec 4 19:12:13 2025 +0100 initial commit diff --git a/battery b/battery new file mode 100755 index 0000000..8d52956 --- /dev/null +++ b/battery @@ -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" + diff --git a/config b/config new file mode 100644 index 0000000..d8701b3 --- /dev/null +++ b/config @@ -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 + diff --git a/cpu_usage b/cpu_usage new file mode 100755 index 0000000..fdb5a58 --- /dev/null +++ b/cpu_usage @@ -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 diff --git a/iface b/iface new file mode 100755 index 0000000..4b97d67 --- /dev/null +++ b/iface @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# Copyright (C) 2014 Julien Bonjean +# Copyright (C) 2014 Alexander Keller + +# 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 . + +#------------------------------------------------------------------------ + +# 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 diff --git a/wifi b/wifi new file mode 100755 index 0000000..18b73f8 --- /dev/null +++ b/wifi @@ -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 +