add waybar and notifcaitons

This commit is contained in:
2026-09-23 00:44:36 +05:00
parent 12fea5c39e
commit 51b4b123dd
14 changed files with 1503 additions and 1 deletions
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
import json
import subprocess
import sys
import signal
def signal_handler(sig, frame):
sys.exit(0)
signal.signal(signal.SIGTERM, signal_handler)
signal.signal(signal.SIGINT, signal_handler)
def get_output(status, artist, title, player):
if not status or status == "Stopped" or not title:
return {"text": "", "tooltip": "No media playing", "class": "stopped"}
if artist and title:
text = f"{artist} - {title}"
elif title:
text = title
else:
return {"text": "", "tooltip": "No media playing", "class": "stopped"}
if status == "Playing":
tooltip = f"▶ {text}"
display = text
elif status == "Paused":
tooltip = f"⏸ {text}"
display = f"⏸ {text}"
else:
tooltip = text
display = text
return {
"text": display[:40] + "..." if len(display) > 40 else display,
"tooltip": tooltip,
"class": status.lower() if status else "stopped"
}
def main():
# Use playerctl follow to get real-time updates
try:
proc = subprocess.Popen(
['playerctl', '--follow', 'metadata', '--format', '{{status}}|||{{artist}}|||{{title}}|||{{playerName}}'],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
text=True
)
for line in proc.stdout:
line = line.strip()
if not line:
output = {"text": "", "tooltip": "No media playing", "class": "stopped"}
else:
parts = line.split('|||')
if len(parts) >= 4:
status, artist, title, player = parts[0], parts[1], parts[2], parts[3]
output = get_output(status, artist, title, player)
else:
output = {"text": "", "tooltip": "No media playing", "class": "stopped"}
print(json.dumps(output), flush=True)
except Exception as e:
print(json.dumps({"text": "", "tooltip": "No media playing", "class": "stopped"}), flush=True)
if __name__ == "__main__":
main()
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
CACHE_FILE="/tmp/monitor-brightness-cache"
PID_FILE="/tmp/monitor-brightness-pid"
SCROLL_FILE="/tmp/monitor-brightness-scroll"
LOCK_FILE="/tmp/monitor-brightness-lock"
get_actual() {
# Prevent concurrent ddcutil calls
exec 9>"$LOCK_FILE"
flock -n 9 || { cat "$CACHE_FILE" 2>/dev/null || echo "50"; return; }
val=$(ddcutil getvcp 10 --display 1 2>/dev/null | grep -oP 'current value =\s*\K[0-9]+')
exec 9>&-
echo "$val"
}
# Initialize cache if missing
[ ! -f "$CACHE_FILE" ] && echo "50" > "$CACHE_FILE"
apply_brightness() {
local value=$1
[ -f "$PID_FILE" ] && kill "$(cat "$PID_FILE")" 2>/dev/null
(
echo $$ > "$PID_FILE"
sleep 0.3
exec 9>"$LOCK_FILE"
flock 9
ddcutil setvcp 10 "$value" --display 1 --noverify 2>/dev/null
exec 9>&-
rm -f "$PID_FILE"
) &
}
case "$1" in
get)
# If scrolled recently, use cache for instant feedback
if [ -f "$SCROLL_FILE" ]; then
age=$(( $(date +%s) - $(stat -c %Y "$SCROLL_FILE") ))
if [ "$age" -lt 3 ]; then
cat "$CACHE_FILE"
exit 0
fi
rm -f "$SCROLL_FILE"
fi
# Otherwise fetch actual value
val=$(get_actual)
if [ -n "$val" ]; then
echo "$val" > "$CACHE_FILE"
echo "$val"
else
cat "$CACHE_FILE"
fi
;;
up)
touch "$SCROLL_FILE"
current=$(cat "$CACHE_FILE")
new=$((current + 5))
[ "$new" -gt 100 ] && new=100
echo "$new" > "$CACHE_FILE"
apply_brightness "$new"
;;
down)
touch "$SCROLL_FILE"
current=$(cat "$CACHE_FILE")
new=$((current - 5))
[ "$new" -lt 0 ] && new=0
echo "$new" > "$CACHE_FILE"
apply_brightness "$new"
;;
esac
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# Power menu using rofi or wofi
# Detect which one is available
if command -v rofi &> /dev/null; then
MENU="rofi -dmenu -i -p Power"
elif command -v wofi &> /dev/null; then
MENU="wofi --dmenu -i -p Power"
else
notify-send "Power Menu" "Neither rofi nor wofi is installed"
exit 1
fi
# Menu options
OPTIONS="⏻ Shutdown\n⟳ Reboot\n⏾ Suspend\n Lock\n Logout"
# Show menu and get choice
CHOICE=$(echo -e "$OPTIONS" | $MENU)
# Execute based on choice
case $CHOICE in
*Shutdown)
systemctl poweroff
;;
*Reboot)
systemctl reboot
;;
*Suspend)
systemctl suspend
;;
*Lock)
# Try different lock commands
if command -v swaylock &> /dev/null; then
swaylock -f -c 000000
elif command -v gtklock &> /dev/null; then
gtklock
else
notify-send "Lock" "No lock screen program found"
fi
;;
*Logout)
swaymsg exit
;;
esac
+68
View File
@@ -0,0 +1,68 @@
#!/usr/bin/env bash
# Check for VPN connections using nmcli device show
# Initialize variables
vpn_status=""
vpn_tooltip=""
vpn_class="disconnected"
vpn_count=0
# Get all VPN devices and their details
while IFS= read -r device; do
if [ -n "$device" ]; then
# Get device type and connection
device_info=$(nmcli device show "$device" 2>/dev/null)
connection=$(echo "$device_info" | grep "GENERAL.CONNECTION:" | awk -F: '{print $2}' | xargs)
device_type=$(echo "$device_info" | grep "GENERAL.TYPE:" | awk -F: '{print $2}' | xargs)
ip_addr=$(echo "$device_info" | grep "IP4.ADDRESS" | head -1 | awk -F: '{print $2}' | xargs)
if [ -n "$connection" ] && [ "$connection" != "--" ]; then
((vpn_count++))
# Determine VPN type
if [[ "$device" == wg* ]]; then
vpn_type="WG"
vpn_icon="🔒"
elif [[ "$device" == tun* ]]; then
vpn_type="OVPN"
vpn_icon="🔒"
else
vpn_type="VPN"
vpn_icon="🔒"
fi
# Build status text
if [ -z "$vpn_status" ]; then
vpn_status="$vpn_icon $vpn_type"
vpn_tooltip="$vpn_type: $connection"
else
vpn_status="$vpn_status | $vpn_icon $vpn_type"
vpn_tooltip="$vpn_tooltip\n$vpn_type: $connection"
fi
# Add IP if available
if [ -n "$ip_addr" ]; then
vpn_tooltip="$vpn_tooltip\nIP: $ip_addr"
fi
# Set class based on first VPN type found
if [ "$vpn_class" = "disconnected" ]; then
if [[ "$device" == wg* ]]; then
vpn_class="connected-wg"
elif [[ "$device" == tun* ]]; then
vpn_class="connected-ovpn"
else
vpn_class="connected"
fi
fi
fi
fi
done < <(nmcli -t -f DEVICE device status | grep -E '^(tun|wg)' | cut -d: -f1)
# If no VPN found, show empty
if [ $vpn_count -eq 0 ]; then
echo "{\"text\":\"\", \"tooltip\":\"No VPN connected\", \"class\":\"disconnected\"}"
else
echo "{\"text\":\"$vpn_status\", \"tooltip\":\"$vpn_tooltip\", \"class\":\"$vpn_class\"}"
fi
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Get weather data from wttr.in with geolocation from ipinfo.io
# You can override with WEATHER_LOCATION environment variable
LOCATION="${WEATHER_LOCATION:-}"
# If no location is set, fetch it from ipinfo.io
if [ -z "$LOCATION" ]; then
LOCATION=$(curl -s "https://ipinfo.io/" | jq -r '.city // empty')
fi
# Fetch weather using wttr.in
if [ -n "$LOCATION" ]; then
WEATHER_DATA=$(curl -s "wttr.in/$LOCATION?format=%c+%t")
TOOLTIP=$(curl -s "wttr.in/$LOCATION?format=%l:+%c+%t+%w+%p+%h")
else
WEATHER_DATA=$(curl -s "wttr.in/?format=%c+%t")
TOOLTIP=$(curl -s "wttr.in/?format=%l:+%c+%t+%w+%p+%h")
fi
# Check if curl was successful
if [ $? -eq 0 ] && [ -n "$WEATHER_DATA" ]; then
echo "{\"text\":\"$WEATHER_DATA\", \"tooltip\":\"$TOOLTIP\"}"
else
echo "{\"text\":\"🌡 N/A\", \"tooltip\":\"Weather data unavailable\"}"
fi