improve structure; move stuff to relevant folders

This commit is contained in:
2025-12-31 14:53:07 +02:00
parent e4296a3251
commit e405894cc2
34 changed files with 1452 additions and 80 deletions

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
PROFILE_FILE="/home/raga/.config/sway/scripts/display-profile/display-profile.conf"
mode_str=""
if [[ -f "$PROFILE_FILE" ]]; then
mode_str="$(awk '$1=="set" && $2=="$dp1_mode" {print $3; found=1} END {if(!found) print ""}' "$PROFILE_FILE" 2>/dev/null)"
fi
# Display-related FontAwesome icon + a short label.
case "$mode_str" in
3840x2160@*|4096x2160@*) echo " 4K";;
1920x1080@*) echo " 1080p";;
"") echo "";;
*) echo "${mode_str}";;
esac

View File

@@ -0,0 +1,75 @@
#!/usr/bin/env bash
set -euo pipefail
# Toggle DP-1 between 4K@165 and 1080p@330 and keep DP-2 positioned flush so
# you don't get a "dead gap" for the mouse.
PROFILE_FILE="/home/raga/.config/sway/scripts/display-profile/display-profile.conf"
MODE_4K="3840x2160@165Hz"
MODE_GAME="1920x1080@330Hz"
# Bar tuning per mode
BAR_HEIGHT_4K="40"
BAR_FONT_4K="pango: FontAwesome, monospace 14"
BAR_HEIGHT_GAME="16"
BAR_FONT_GAME="pango: FontAwesome, monospace 8"
# DP-2 bar settings (static)
DP2_BAR_HEIGHT="24"
DP2_BAR_FONT="pango: FontAwesome, monospace 10"
get_current_profile_mode() {
# Reads the last-written profile state instead of querying the monitor.
# This makes toggling deterministic even if the display reports odd modes.
if [[ ! -f "$PROFILE_FILE" ]]; then
echo "$MODE_4K"
return
fi
# Example line: set $dp1_mode 3840x2160@165Hz
awk '$1=="set" && $2=="$dp1_mode" {print $3; found=1} END {if(!found) exit 1}' "$PROFILE_FILE" 2>/dev/null \
|| echo "$MODE_4K"
}
write_profile() {
local dp1_mode="$1"
local dp1_bar_height="$2"
local dp1_bar_font="$3"
local dp2_x="$4"
local tmp
tmp="$(mktemp)"
cat >"$tmp" <<EOF
# Autogenerated by display-profile-toggle.sh. Manual edits will be overwritten.
set \$dp1_mode ${dp1_mode}
set \$dp1_bar_height ${dp1_bar_height}
set \$dp1_bar_font ${dp1_bar_font}
set \$dp2_x ${dp2_x}
set \$dp2_bar_height ${DP2_BAR_HEIGHT}
set \$dp2_bar_font ${DP2_BAR_FONT}
EOF
mkdir -p "$(dirname "$PROFILE_FILE")"
mv -f "$tmp" "$PROFILE_FILE"
}
main() {
local current_mode
current_mode="$(get_current_profile_mode)"
if [[ "$current_mode" == "$MODE_4K" ]]; then
# Switch to game mode (1080p @ high refresh)
write_profile "$MODE_GAME" "$BAR_HEIGHT_GAME" "$BAR_FONT_GAME" "1920"
else
# Switch back to 4K
write_profile "$MODE_4K" "$BAR_HEIGHT_4K" "$BAR_FONT_4K" "3840"
fi
swaymsg reload >/dev/null
}
main "$@"

View File

@@ -0,0 +1,12 @@
# Default display profile
# Rewritten and toggled in `display-profile-toggle.sh`
# DP-1 (4K / gaming output)
set $dp1_mode 3840x2160@165Hz
set $dp1_bar_height 40
set $dp1_bar_font pango: FontAwesome, monospace 14
# DP-2 (secondary output)
set $dp2_x 3840
set $dp2_bar_height 24
set $dp2_bar_font pango: FontAwesome, monospace 10

View File

@@ -0,0 +1,62 @@
#!/bin/bash
set -Eeu -o pipefail
# Bluetooth script for i3status-rust
# Shows connected Bluetooth devices
BT_ICON=""
# Check if bluetoothctl is available
if ! command -v bluetoothctl >/dev/null 2>&1; then
echo "$BT_ICON Not available"
exit 0
fi
# Check if Bluetooth is powered on
BLUETOOTH_POWERED=$(bluetoothctl show | grep "Powered:" | awk '{print $2}')
if [ "$BLUETOOTH_POWERED" != "yes" ]; then
echo "$BT_ICON Off"
exit 0
fi
# Get connected devices
CONNECTED_DEVICES=$(bluetoothctl devices Connected | grep "^Device" | awk '{for(i=3;i<=NF;i++) printf "%s ", $i; print ""}' | sed 's/ $//')
if [ -z "$CONNECTED_DEVICES" ]; then
echo "$BT_ICON No devices"
else
# Limit the display to first 2 devices to avoid cluttering the bar
DEVICE_COUNT=$(echo "$CONNECTED_DEVICES" | wc -w)
if [ "$DEVICE_COUNT" -le 2 ]; then
echo "$BT_ICON $CONNECTED_DEVICES"
else
FIRST_TWO=$(echo "$CONNECTED_DEVICES" | cut -d' ' -f1-2)
echo "$BT_ICON $FIRST_TWO (+$((DEVICE_COUNT - 2)))"
fi
fi
# Handle click events (for i3status-rust custom block)
if [ "${BLOCK_BUTTON:-}" = "1" ]; then
# Left click - show all connected devices with details
DETAILED_DEVICES=$(bluetoothctl devices Connected | while read -r line; do
MAC=$(echo "$line" | awk '{print $2}')
NAME=$(echo "$line" | awk '{for(i=3;i<=NF;i++) printf "%s ", $i; print ""}' | sed 's/ $//')
echo "$NAME ($MAC)"
done)
if [ -n "$DETAILED_DEVICES" ]; then
notify-send "Bluetooth Devices" "$DETAILED_DEVICES" -t 5000
else
notify-send "Bluetooth" "No devices connected" -t 3000
fi
elif [ "${BLOCK_BUTTON:-}" = "3" ]; then
# Right click - open bluetooth manager
if command -v blueman-manager >/dev/null 2>&1; then
blueman-manager >/dev/null 2>&1 &
elif command -v gnome-bluetooth-panel >/dev/null 2>&1; then
gnome-bluetooth-panel >/dev/null 2>&1 &
else
notify-send "Bluetooth" "No Bluetooth manager found" -t 3000
fi
fi

View File

@@ -0,0 +1,5 @@
#!/bin/bash
FOCUSED=$(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | .name')
echo "$FOCUSED"

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# Find a random image file
#IMAGE=$(find /run/media/raga/970/qBittorrent/nsfw/xd -type f \( -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' \) | shuf -n 1)
IMAGE=$(find /run/media/raga/970/images/cars/wallpaper -type f \( -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' \) | shuf -n 1)
if [ -n "$IMAGE" ]; then
echo "Image: $IMAGE"
# Try to get image dimensions using identify (ImageMagick)
DIMENSIONS=$(identify -format "%wx%h" "$IMAGE" 2>/dev/null)
if [ -n "$DIMENSIONS" ]; then
echo "Dimensions: $DIMENSIONS"
WIDTH=$(echo "$DIMENSIONS" | cut -d'x' -f1)
HEIGHT=$(echo "$DIMENSIONS" | cut -d'x' -f2)
# Determine if portrait (height > width) or landscape
if [ "$HEIGHT" -gt "$WIDTH" ]; then
# Portrait image - use "fit" to maintain aspect ratio
echo "Portrait image - using fit"
swaymsg "output * bg \"$IMAGE\" fit"
else
# Landscape image - use "fill" to fill the screen
echo "Landscape image - using fill"
swaymsg "output * bg \"$IMAGE\" fill"
fi
else
# Fallback to fill if we can't determine dimensions
echo "Could not determine dimensions - using fill"
swaymsg "output * bg \"$IMAGE\" fill"
fi
fi

View File

@@ -0,0 +1,115 @@
#!/bin/bash
set -Eeu -o pipefail
# Improved weather script for i3status-rust using JSON API
# Based on the original weather script but optimized for Sway/i3status-rust
# Location (defaults to Pärnu as in your original script)
VALUE_WEATHER_LOCATION=${weather_location:-"Pärnu"}
VALUE_WEATHER_ERROR_MESSAGE=${error_message:-"⛔"}
# Determine units to use for temperature
# We don't supply a default here because wttr.in is "smart" enough to choose for us
WEATHER_UNIT=${weather_unit:-""}
if [ -n "${WEATHER_UNIT}" ]; then
WEATHER_UNIT="&${WEATHER_UNIT}"
fi
# Use JSON API to get all data in a single request
VALUE_FETCH_WEATHER_URL="https://wttr.in/${VALUE_WEATHER_LOCATION}?format=j1"
# Get weather data using JSON API
WEATHER_JSON=$(curl -sS "$VALUE_FETCH_WEATHER_URL" 2>/dev/null || echo "{}")
# Check for errors
if echo "$WEATHER_JSON" | grep -q "Unknown location"; then
echo "${VALUE_WEATHER_ERROR_MESSAGE}"
exit 0
fi
# Extract data using jq (should be available on most systems)
if command -v jq &>/dev/null; then
# Extract current weather condition and temperature
WEATHER_CONDITION=$(echo "$WEATHER_JSON" | jq -r '.current_condition[0].weatherDesc[0].value' 2>/dev/null || echo "")
TEMP_C=$(echo "$WEATHER_JSON" | jq -r '.current_condition[0].temp_C' 2>/dev/null || echo "")
# Extract sunrise and sunset times
SUNRISE=$(echo "$WEATHER_JSON" | jq -r '.weather[0].astronomy[0].sunrise' 2>/dev/null || echo "")
SUNSET=$(echo "$WEATHER_JSON" | jq -r '.weather[0].astronomy[0].sunset' 2>/dev/null || echo "")
# Convert to simple format if we have data
if [ -n "$WEATHER_CONDITION" ] && [ -n "$TEMP_C" ]; then
# Map weather conditions to icons (simplified)
case "$WEATHER_CONDITION" in
*"Sunny"*|*"Clear"*) ICON="☀️";;
*"Partly cloudy"*|*"Cloudy"*) ICON="⛅";;
*"Overcast"*) ICON="☁️";;
*"Rain"*|*"Drizzle"*) ICON="🌧️";;
*"Snow"*) ICON="❄️";;
*"Thunder"*) ICON="⛈️";;
*"Fog"*|*"Mist"*) ICON="🌫️";;
*) ICON="🌤️";;
esac
WEATHER="${ICON} ${TEMP_C}°C"
# Format sunrise/sunset times (convert from "09:10 AM" to "09:10")
if [ -n "$SUNRISE" ] && [ -n "$SUNSET" ]; then
# Remove AM/PM and convert to 24-hour format
SUNRISE_24=$(echo "$SUNRISE" | sed 's/ AM//;s/ PM//;s/^0//' | awk -F: '{if($1==12) print "00:"$2; else if($1<12) print $1":"$2; else print $1":"$2}')
SUNSET_24=$(echo "$SUNSET" | sed 's/ AM//;s/ PM//;s/^0//' | awk -F: '{if($1==12) print "00:"$2; else if($1<12) print $1":"$2; else print $1":"$2}')
# Remove leading zeros from hours for consistency
SUNRISE_24=$(echo "$SUNRISE_24" | sed 's/^0//')
SUNSET_24=$(echo "$SUNSET_24" | sed 's/^0//')
SUNRISE_SUNSET_TEXT=" (${SUNRISE_24}-${SUNSET_24})"
else
SUNRISE_SUNSET_TEXT=""
fi
# Output for i3status-rust (plain text)
echo "${WEATHER}${SUNRISE_SUNSET_TEXT}"
else
echo "${VALUE_WEATHER_ERROR_MESSAGE}"
fi
else
# Fallback to original method if jq is not available
echo "⚠️ jq not found, using fallback method"
# Get basic weather data
VALUE_WEATHER_FORMAT=${weather_format:-"%c%f"}
VALUE_WEATHER_FORMAT="?format=${VALUE_WEATHER_FORMAT}"
WEATHER=$(curl -sS "https://wttr.in/${VALUE_WEATHER_LOCATION}${VALUE_WEATHER_FORMAT}${WEATHER_UNIT}" 2>/dev/null || echo "${VALUE_WEATHER_ERROR_MESSAGE}")
# Get sunrise/sunset data
VALUE_SUNSET_SUNRISE_FORMAT="?format=%S-%s"
SUNRISE_SUNSET=$(curl -sS "https://wttr.in/${VALUE_WEATHER_LOCATION}${VALUE_SUNSET_SUNRISE_FORMAT}${WEATHER_UNIT}" 2>/dev/null || echo "")
if [ -n "$SUNRISE_SUNSET" ]; then
SUNRISE_VALUE=$(echo ${SUNRISE_SUNSET} | cut -c 1-5)
SUNSET_VALUE=$(echo ${SUNRISE_SUNSET} | cut -c 7-11)
SUNRISE_SUNSET_TEXT=" (${SUNRISE_VALUE}-${SUNSET_VALUE})"
else
SUNRISE_SUNSET_TEXT=""
fi
# Check for errors
if echo "${WEATHER}" | grep -q -P "Unknown\slocation"; then
WEATHER=${VALUE_WEATHER_ERROR_MESSAGE}
fi
# Output for i3status-rust (plain text)
echo "${WEATHER}${SUNRISE_SUNSET_TEXT}"
fi
# Handle click events (for i3status-rust custom block)
if [ "${BLOCK_BUTTON:-}" = "1" ]; then
# Left click - show detailed weather using JSON
DETAILED_WEATHER=$(curl -sS "https://wttr.in/${VALUE_WEATHER_LOCATION}?format=%l:+%c+%f+%h+%p+%P+%m+%w+%S-%s" 2>/dev/null || echo "${VALUE_WEATHER_ERROR_MESSAGE}")
notify-send "Weather Details" "$DETAILED_WEATHER" -t 10000
elif [ "${BLOCK_BUTTON:-}" = "3" ]; then
# Right click - open weather website
xdg-open "https://wttr.in/${VALUE_WEATHER_LOCATION}" >/dev/null 2>&1 &
fi

View File

@@ -0,0 +1,10 @@
#!/bin/bash
MODE=$(swaymsg -r -t get_binding_state 2>/dev/null | jq -r '.name // "default"')
ICON=""
if [ "$MODE" = "OSRS" ]; then
echo "$ICON ON"
else
echo "$ICON OFF"
fi

View File

@@ -0,0 +1,10 @@
#!/bin/bash
MODE_NAME="OSRS"
CURRENT=$(swaymsg -r -t get_binding_state 2>/dev/null | jq -r '.name // "default"')
if [ "$CURRENT" = "$MODE_NAME" ]; then
swaymsg mode default >/dev/null
else
swaymsg mode "$MODE_NAME" >/dev/null
fi

View File

@@ -0,0 +1,14 @@
#!/bin/bash
# Kill any existing volume notification
pkill -f "notify-send.*Volume"
# Get current volume and mute status
volume=$(pactl get-sink-volume @DEFAULT_SINK@ | head -n1 | awk '{print $5}')
muted=$(pactl get-sink-mute @DEFAULT_SINK@ | awk '{print $2}')
if [ "$muted" = "yes" ]; then
notify-send -t 1000 "Volume" "Muted"
else
notify-send -t 1000 "Volume" "$volume"
fi