This commit is contained in:
2025-11-12 15:07:25 -05:00
4 changed files with 175 additions and 10 deletions
+140
View File
@@ -0,0 +1,140 @@
#!/usr/bin/env bash
# prints a battery icon + either percentage or time remaining
# depends (optional): upower or acpi; otherwise falls back to /sys
# config: icons from nerd fonts / font awesome
icon_empty=""; # very low
icon_low=""; # low
icon_mid=""; # medium
icon_high=""; # high
icon_full=""; # full
icon_charge=""; # charging bolt
icon_plug=""; # plugged/full
icon_alert=""; # critical
# config: low/critical thresholds
low_threshold=20;
crit_threshold=10;
state_file="${XDG_CACHE_HOME:-$HOME/.cache}/polybar_battery_mode";
mode="percent";
if [[ -f "$state_file" ]]; then
mode="$(cat "$state_file" 2>/dev/null | tr -d '\n' )";
fi
bat_path="$(ls -d /sys/class/power_supply/BAT* 2>/dev/null | head -n1)";
if [[ -z "$bat_path" ]]; then
echo "${icon_alert} no battery";
exit 0;
fi
# helpers
pick_icon() {
local pct="$1";
local status="$2";
local base;
if (( pct == 100 )); then base="^~^"
elif (( pct >= 95 )); then base="$icon_full";
elif (( pct >= 75 )); then base="$icon_high";
elif (( pct >= 50 )); then base="$icon_mid";
elif (( pct >= 25 )); then base="$icon_low";
else base="$icon_empty";
fi
# overlay/override for charging or full on ac power
if [[ "$status" == "Charging" ]]; then
echo "$icon_charge $base";
elif [[ "$status" == "Full" || "$status" == "Not charging" ]]; then
echo "$icon_plug $base";
else
echo "$base";
fi
}
fmt_time() {
# normalize various formats (e.g., "1.5 hours", "02:41:13")
local raw="$1";
if [[ "$raw" =~ ^[0-9]+:[0-9]{2}:[0-9]{2}$ ]]; then
# hh:mm:ss -> XhYm
IFS=':' read -r h m s <<<"$raw";
printf "%sh%sm" "$h" "$m";
elif [[ "$raw" =~ ^([0-9]+(\.[0-9]+)?)\ hours?$ ]]; then
# upower: "1.4 hours"
local hours="${raw% hours}";
hours="${hours% hour}";
# convert decimal hours to h m
local total_min;
total_min="$(python - <<'PY'
import math,sys
h=float(sys.stdin.read().strip())
m=round((h-int(h))*60)
print(f"{int(h)}h{m}m")
PY
<<<"$hours")";
printf "%s" "$total_min";
else
printf "%s" "$raw";
fi
}
percentage="";
status="";
eta=""; # time to empty or to full
# try upower first (dbus-based, used by many desktops)
if command -v upower >/dev/null 2>&1; then
dev="$(upower -e | grep -m1 BAT)";
if [[ -n "$dev" ]]; then
info="$(upower -i "$dev" 2>/dev/null)";
status="$(awk -F': *' '/^\s*state:/{print $2}' <<<"$info")";
percentage="$(awk -F': *' '/^\s*percentage:/{print $2}' <<<"$info" | tr -d '% ')";
if [[ "$status" == "charging" ]]; then
eta="$(awk -F': *' '/time to full/{print $2}' <<<"$info")";
elif [[ "$status" == "discharging" ]]; then
eta="$(awk -F': *' '/time to empty/{print $2}' <<<"$info")";
fi
# normalize capitalization
status="$(tr '[:lower:]' '[:upper:]' <<<"${status:0:1}")${status:1}";
fi
fi
# fallback: acpi (reads /sys or /proc and calculates eta)
if [[ -z "$percentage" || -z "$status" ]] && command -v acpi >/dev/null 2>&1; then
line="$(acpi -b 2>/dev/null | head -n1)";
# examples: "Battery 0: Discharging, 93%, 02:41:13 remaining"
# "Battery 0: Charging, 80%, 00:20:00 until charged"
status="$(awk -F', *' -v OFS=',' '{split($1,a,": "); print a[2]}' <<<"$line")";
percentage="$(awk -F', *' '{gsub("%","",$2); print $2}' <<<"$line")";
eta="$(awk -F', *' '{print $3}' <<<"$line" | sed -E 's/(remaining|until charged)//g' | xargs)";
fi
# final fallback: sysfs (percentage + status only)
if [[ -z "$percentage" || -z "$status" ]]; then
if [[ -r "$bat_path/capacity" && -r "$bat_path/status" ]]; then
percentage="$(cat "$bat_path/capacity" 2>/dev/null)";
status="$(cat "$bat_path/status" 2>/dev/null)";
fi
fi
# guard rails
if [[ -z "$percentage" ]]; then
echo "${icon_alert} n/a";
exit 0;
fi
icon="$(pick_icon "$percentage" "$status")";
# add critical marker if really low and discharging
if (( percentage <= crit_threshold )) && [[ "$status" == "Discharging" ]]; then
icon="${icon_alert} ${icon}";
fi
# output based on mode
if [[ "$mode" == "time" && -n "$eta" ]]; then
echo "${icon} $(fmt_time "$eta")";
else
echo "${icon} ${percentage}%";
fi
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# toggles display mode (percent <-> time) for the battery module
state_file="${XDG_CACHE_HOME:-$HOME/.cache}/polybar_battery_mode";
current="percent";
if [[ -f "$state_file" ]]; then
current="$(cat "$state_file" 2>/dev/null | tr -d '\n')";
fi
if [[ "$current" == "percent" ]]; then
echo "time" > "$state_file";
else
echo "percent" > "$state_file";
fi
+14 -1
View File
@@ -14,7 +14,7 @@
/* IMPORT CSS */
@import url(https://clearvision.github.io/ClearVision-v7/main.css);
@import url('https://raw.githubusercontent.com/ClearVision/ClearVision-v7/master/ClearVision-v7.theme.css');
@import url('https://fonts.googleapis.com/css?family=Muli&display=swap');
@import url('https://fonts.googleapis.com/css?family=Quicksand&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Playwrite+NZ:wght@100..400&display=swap');
@@ -349,7 +349,20 @@
color: rgb(0, 255, 128) !important;
}
[aria-label="Add Role"] {
background-color: black !important;
}
[aria-label="Add Role"]:first-child {
border-radius: 0 0 10px 10px;
}
.leading_c38106::before,.leading_c38106::after {
display: none;
}
/* popup */
.standardSidebarView__23e6b {
background: rgb(0 0 0 / 90%);
}
+9 -9
View File
@@ -53,8 +53,8 @@ if [ "$answer" != "y" ]; then
fi
# Make temporary directory
mkdir $USERTEMP/Downloads/tempinstall || ""
cd $USERTEMP/Downloads/tempinstall
mkdir /home/$USERTEMP/Downloads/tempinstall || ""
cd /home/$USERTEMP/Downloads/tempinstall
# Configuration Files
git clone https://github.com/ION606/config-backup.git
@@ -63,7 +63,7 @@ cd config-backup
# sway
mv -f waybar/config /etc/xdg/waybar/
mv -f waybar/style.css /etc/xdg/waybar/
mv -f config $USERTEMP/.config/sway/config
mv -f config /home/$USERTEMP/.config/sway/config
# replace "ion606" with the selected user
sed -i "s/ion606/$USERTEMP/g" config
@@ -83,11 +83,11 @@ mv -f terminal/alacritty.toml /home/$USERTEMP/.config/alacritty/
mv -f terminal/starship.toml /home/$USERTEMP/.config/
# battery
mkdir -p $USERTEMP/auto-cpufreq/auto-cpufreq.conf
mv auto-cpufreq.conf $USERTEMP/auto-cpufreq/auto-cpufreq.conf
mkdir -p /home/$USERTEMP/auto-cpufreq/auto-cpufreq.conf
mv auto-cpufreq.conf /home/$USERTEMP/auto-cpufreq/auto-cpufreq.conf
# set up automations in child process
mkdir -p $USERTEMP/.automations && cp -r -f auto/* $USERTEMP/.automations/ && $(sudo pacman -Sy --needed --noconfirm dunst && sudo bash $USERTEMP/.automations/setupauto.sh $USERTEMP &>$USERTEMP/setuplogs.log) &
mkdir -p /home/$USERTEMP/.automations && cp -r -f auto/* /home/$USERTEMP/.automations/ && $(sudo pacman -Sy --needed --noconfirm dunst && sudo bash /home/$USERTEMP/.automations/setupauto.sh /home/$USERTEMP &> /home/$USERTEMP/setuplogs.log) &
# Installs
# Librewolf
@@ -111,11 +111,11 @@ mv -f Librewolf/chrome /home/$USERTEMP/.librewolf/
npm install -g @bitwarden/cli alacritty-themes typescript || echo "failed to install Typescript!"
mkdir -p $USERTEMP/.icons
echo -e "https://www.gnome-look.org/p/1305251\nhttps://www.gnome-look.org/p/2091068" >$USERTEMP/.icons/links.txt
mkdir -p /home/$USERTEMP/.icons
echo -e "https://www.gnome-look.org/p/1305251\nhttps://www.gnome-look.org/p/2091068" > /home/$USERTEMP/.icons/links.txt
alacritty-themes --create && alacritty-themes Hyper || echo "alacritty theme install failed!"
cp -r $USERTEMP/.config/wofi/ wofi >/dev/null 2>&1 &
cp -r /home/$USERTEMP/.config/wofi/ wofi >/dev/null 2>&1 &
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
# Remove old programs