add waybar config

This commit is contained in:
2025-12-13 21:43:11 +08:00
parent 3ccb2d8186
commit 40f3d0e845
46 changed files with 2429 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
#!/usr/bin/env bash
#
# A helper script that syncs fzf colors with the current Waybar theme
#
main() {
local wcss="$HOME/.config/waybar/current-theme.css"
local wtheme fcolors
wtheme=$(sed 1q "$wcss" | awk '{print $2}')
fcolors="$HOME/.config/waybar/themes/fzf/$wtheme.txt"
# Extract theme colors starting from line 3 up to (but not including) the
# first blank line
local wcolors
wcolors=$(sed -n '3,${/^ *$/Q;p}' "$wcss")
local element color hex
fcconf=()
while read -r element color; do
read -r _ _ hex < <(grep " $color " <<< "$wcolors")
hex=${hex%;}
fcconf+=("--color=$element:$hex")
done < "$fcolors"
}
main

64
waybar/scripts/backlight.sh Executable file
View File

@@ -0,0 +1,64 @@
#!/usr/bin/env bash
#
# Adjust screen brightness and send a notification with the current level
#
# Requirements:
# - brightnessctl
# - notify-send (libnotify)
#
# Author: Jesse Mirabel <sejjymvm@gmail.com>
# Created: August 28, 2025
# License: MIT
VALUE=1
print-usage() {
local script=${0##*/}
cat <<- EOF
USAGE: $script [OPTIONS]
Adjust screen brightness and send a notification with the current level
OPTIONS:
up <value> Increase brightness by <value>
down <value> Decrease brightness by <value>
Default value: $VALUE
EXAMPLES:
Increase brightness:
$ $script up
Decrease brightness by 5:
$ $script down 5
EOF
exit 1
}
set-brightness() {
local op
case $action in
'up') op='+' ;;
'down') op='-' ;;
esac
brightnessctl -n set "${value}%${op}" > /dev/null
local level
level=$(brightnessctl -m | awk -F ',' '{print $4}')
notify-send "Brightness: $level" -h int:value:"$level" -i 'contrast' -r 2825
}
main() {
action=$1
value=${2:-$VALUE}
! ((value > 0)) && print-usage
case $action in
'up' | 'down') set-brightness ;;
*) print-usage ;;
esac
}
main "$@"

141
waybar/scripts/bluetooth.sh Executable file
View File

@@ -0,0 +1,141 @@
#!/usr/bin/env bash
#
# Scan, select, pair, and connect to Bluetooth devices
#
# Requirements:
# - bluetoothctl (bluez-utils)
# - fzf
# - notify-send (libnotify)
#
# Author: Jesse Mirabel <sejjymvm@gmail.com>
# Created: August 19, 2025
# License: MIT
fcconf=()
# Get fzf color config
# shellcheck disable=SC1090,SC2154
. ~/.config/waybar/scripts/_fzf_colorizer.sh 2> /dev/null || true
# If the file is missing, fzf will fall back to its default colors
RED='\033[1;31m'
RST='\033[0m'
TIMEOUT=10
ensure-on() {
local status
status=$(bluetoothctl show | awk '/PowerState/ {print $2}')
case $status in
'off') bluetoothctl power on > /dev/null ;;
'off-blocked')
rfkill unblock bluetooth
local i new_status
for ((i = 1; i <= TIMEOUT; i++)); do
printf '\rUnblocking Bluetooth... (%d/%d)' $i $TIMEOUT
new_status=$(bluetoothctl show | awk '/PowerState/ {print $2}')
if [[ $new_status == 'on' ]]; then
break
fi
sleep 1
done
# Bluetooth could be hard blocked
if [[ $new_status != 'on' ]]; then
notify-send 'Bluetooth' 'Failed to unblock' -i 'package-purge'
return 1
fi
;;
*) return 0 ;;
esac
notify-send 'Bluetooth On' -i 'network-bluetooth-activated' -r 1925
}
get-device-list() {
bluetoothctl --timeout $TIMEOUT scan on > /dev/null &
local i num
for ((i = 1; i <= TIMEOUT; i++)); do
printf '\rScanning for devices... (%d/%d)' $i $TIMEOUT
printf '\n%bPress [q] to stop%b\n\n' "$RED" "$RST"
num=$(bluetoothctl devices | grep -c 'Device')
printf '\rDevices: %s' "$num"
printf '\033[3A'
read -rs -n 1 -t 1
if [[ $REPLY == [Qq] ]]; then
break
fi
done
printf '\n%bScanning stopped.%b\n\n' "$RED" "$RST"
list=$(bluetoothctl devices | sed 's/^Device //')
if [[ -z $list ]]; then
notify-send 'Bluetooth' 'No devices found' -i 'package-broken'
return 1
fi
}
select-device() {
local header
header=$(printf '%-17s %s' 'Address' 'Name')
local opts=(
'--border=sharp'
'--border-label= Bluetooth Devices '
'--ghost=Search'
"--header=$header"
'--height=~100%'
'--highlight-line'
'--info=inline-right'
'--pointer='
'--reverse'
"${fcconf[@]}"
)
address=$(fzf "${opts[@]}" <<< "$list" | awk '{print $1}')
if [[ -z $address ]]; then
return 1
fi
local connected
connected=$(bluetoothctl info "$address" | awk '/Connected/ {print $2}')
if [[ $connected == 'yes' ]]; then
notify-send 'Bluetooth' 'Already connected to this device' \
-i 'package-install'
return 1
fi
}
pair-and-connect() {
local paired
paired=$(bluetoothctl info "$address" | awk '/Paired/ {print $2}')
if [[ $paired == 'no' ]]; then
printf 'Pairing...'
if ! timeout $TIMEOUT bluetoothctl pair "$address" > /dev/null; then
notify-send 'Bluetooth' 'Failed to pair' -i 'package-purge'
return 1
fi
fi
printf '\nConnecting...'
if ! timeout $TIMEOUT bluetoothctl connect "$address" > /dev/null; then
notify-send 'Bluetooth' 'Failed to connect' -i 'package-purge'
return 1
fi
notify-send 'Bluetooth' 'Successfully connected' -i 'package-install'
}
main() {
tput civis
ensure-on || exit 1
get-device-list || exit 1
tput cnorm
select-device || exit 1
pair-and-connect || exit 1
}
main

114
waybar/scripts/network.sh Executable file
View File

@@ -0,0 +1,114 @@
#!/usr/bin/env bash
#
# Scan, select, and connect to Wi-Fi networks
#
# Requirements:
# - nmcli (networkmanager)
# - fzf
# - notify-send (libnotify)
#
# Author: Jesse Mirabel <sejjymvm@gmail.com>
# Created: August 11, 2025
# License: MIT
fcconf=()
# Get fzf color config
# shellcheck disable=SC1090,SC2154
. ~/.config/waybar/scripts/_fzf_colorizer.sh 2> /dev/null || true
# If the file is missing, fzf will fall back to its default colors
RED='\033[1;31m'
RST='\033[0m'
TIMEOUT=5
ensure-enabled() {
local radio
radio=$(nmcli radio wifi)
if [[ $radio == 'enabled' ]]; then
return 0
fi
nmcli radio wifi on
local i state
for ((i = 1; i <= TIMEOUT; i++)); do
printf '\rEnabling Wi-Fi... (%d/%d)' $i $TIMEOUT
state=$(nmcli -t -f STATE general)
# If STATE returns anything other than this, we assume that Wi-Fi is
# fully enabled
if [[ $state != 'connected (local only)' ]]; then
break
fi
sleep 1
done
notify-send 'Wi-Fi Enabled' -i 'network-wireless-on' -r 1125
}
get-network-list() {
nmcli device wifi rescan
local i
for ((i = 1; i <= TIMEOUT; i++)); do
printf '\rScanning for networks... (%d/%d)' $i $TIMEOUT
list=$(timeout 1 nmcli device wifi list)
networks=$(tail -n +2 <<< "$list" | awk '$2 != "--"')
if [[ -n $networks ]]; then
break
fi
done
printf '\n%bScanning stopped.%b\n\n' "$RED" "$RST"
if [[ -z $networks ]]; then
notify-send 'Wi-Fi' 'No networks found' -i 'package-broken'
return 1
fi
}
select-network() {
local header
header=$(head -n 1 <<< "$list")
local opts=(
'--border=sharp'
'--border-label= Wi-Fi Networks '
'--ghost=Search'
"--header=$header"
'--height=~100%'
'--highlight-line'
'--info=inline-right'
'--pointer='
'--reverse'
"${fcconf[@]}"
)
bssid=$(fzf "${opts[@]}" <<< "$networks" | awk '{print $1}')
if [[ -z $bssid ]]; then
return 1
fi
if [[ $bssid == '*' ]]; then
notify-send 'Wi-Fi' 'Already connected to this network' \
-i 'package-install'
return 1
fi
}
connect-to-network() {
printf 'Connecting...\n'
if ! nmcli --ask device wifi connect "$bssid"; then
notify-send 'Wi-Fi' 'Failed to connect' -i 'package-purge'
return 1
fi
notify-send 'Wi-Fi' 'Successfully connected' -i 'package-install'
}
main() {
tput civis
ensure-enabled || exit 1
get-network-list || exit 1
tput cnorm
select-network || exit 1
connect-to-network || exit 1
}
main

51
waybar/scripts/power-menu.sh Executable file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env bash
#
# Launch a power menu
#
# Requirements:
# - fzf
#
# Author: Jesse Mirabel <sejjymvm@gmail.com>
# Created: August 19, 2025
# License: MIT
fcconf=()
# Get fzf color config
# shellcheck disable=SC1090,SC2154
. ~/.config/waybar/scripts/_fzf_colorizer.sh 2> /dev/null || true
# If the file is missing, fzf will fall back to its default colors
main() {
local list=(
'Lock'
'Shutdown'
'Reboot'
'Logout'
'Hibernate'
'Suspend'
)
local opts=(
'--border=sharp'
'--border-label= Power Menu '
'--height=~100%'
'--highlight-line'
'--no-input'
'--pointer='
'--reverse'
"${fcconf[@]}"
)
local selected
selected=$(printf '%s\n' "${list[@]}" | fzf "${opts[@]}")
case $selected in
'Lock') loginctl lock-session ;;
'Shutdown') systemctl poweroff ;;
'Reboot') systemctl reboot ;;
'Logout') loginctl terminate-session "$XDG_SESSION_ID" ;;
'Hibernate') systemctl hibernate ;;
'Suspend') systemctl suspend ;;
*) exit 1 ;;
esac
}
main

115
waybar/scripts/system-update.sh Executable file
View File

@@ -0,0 +1,115 @@
#!/usr/bin/env bash
#
# Check for official and AUR package updates and upgrade them. When run with the
# 'module' argument, output the status icon and update counts in JSON format for
# Waybar
#
# Requirements:
# - checkupdates (pacman-contrib)
# - notify-send (libnotify)
# - optional: an AUR helper
#
# Author: Jesse Mirabel <sejjymvm@gmail.com>
# Created: August 16, 2025
# License: MIT
GRN='\033[1;32m'
BLU='\033[1;34m'
RST='\033[0m'
TIMEOUT=10
HELPERS=('aura' 'paru' 'pikaur' 'trizen' 'yay')
detect-helper() {
local h
for h in "${HELPERS[@]}"; do
if command -v "$h" > /dev/null; then
helper=$h
break
fi
done
}
check-updates() {
is_online=true
repo=0
aur=0
local rout rstat
rout=$(timeout $TIMEOUT checkupdates)
rstat=$?
# 2 means no updates are available
if ((rstat != 0 && rstat != 2)); then
is_online=false
return 1
fi
repo=$(grep -cve '^\s*$' <<< "$rout")
if [[ -z $helper ]]; then
return 0
fi
local aout astat
aout=$(timeout $TIMEOUT "$helper" -Quaq)
astat=$?
# Return only if the exit status is non-zero and there is an error
# message
if ((${#aout} > 0 && astat != 0)); then
is_online=false
return 1
fi
aur=$(grep -cve '^\s*$' <<< "$aout")
}
update-packages() {
printf '\n%bUpdating pacman packages...%b\n' "$BLU" "$RST"
sudo pacman -Syu
if [[ -n $helper ]]; then
printf '\n%bUpdating AUR packages...%b\n' "$BLU" "$RST"
"$helper" -Syu
fi
notify-send 'Update Complete' -i 'package-install'
printf '\n%bUpdate Complete!%b\n' "$GRN" "$RST"
read -rs -n 1 -p 'Press any key to exit...'
}
display-module() {
if [[ $is_online == false ]]; then
echo "{ \"text\": \"󰒑\", \"tooltip\": \"Cannot fetch updates. Right-click to retry.\" }"
return 0
fi
local tooltip="<b>Official</b>: $repo"
if [[ -n $helper ]]; then
tooltip+="\n<b>AUR($helper)</b>: $aur"
fi
local total=$((repo + aur))
if ((total == 0)); then
echo "{ \"text\": \"󰸟\", \"tooltip\": \"No updates available\" }"
else
echo "{ \"text\": \"󰄠\", \"tooltip\": \"$tooltip\" }"
fi
}
main() {
detect-helper
case $1 in
'module')
check-updates
display-module
;;
*)
printf '%bChecking for updates...%b' "$BLU" "$RST"
check-updates
update-packages
# use signal to update the module
pkill -RTMIN+1 waybar
;;
esac
}
main "$@"

143
waybar/scripts/volume.sh Executable file
View File

@@ -0,0 +1,143 @@
#!/usr/bin/env bash
#
# Adjust default device volume and send a notification with the current level
#
# Requirements:
# - pactl (libpulse)
# - notify-send (libnotify)
#
# Author: Jesse Mirabel <sejjymvm@gmail.com>
# Created: September 07, 2025
# License: MIT
VALUE=1
MIN=0
MAX=100
print-usage() {
local script=${0##*/}
cat <<- EOF
USAGE: $script [OPTIONS]
Adjust default device volume and send a notification with the current level
OPTIONS:
input Set device as '@DEFAULT_SOURCE@'
output Set device as '@DEFAULT_SINK@'
mute Toggle device mute
raise <value> Raise volume by <value>
lower <value> Lower volume by <value>
Default value: $VALUE
EXAMPLES:
Toggle microphone mute:
$ $script input mute
Raise speaker volume:
$ $script output raise
Lower speaker volume by 5:
$ $script output lower 5
EOF
exit 1
}
check-muted() {
local muted
muted=$(pactl "get-$dev_mute" "$dev" | awk '{print $2}')
local state
case $muted in
'yes') state='Muted' ;;
'no') state='Unmuted' ;;
esac
echo "$state"
}
get-volume() {
pactl "get-$dev_vol" "$dev" | awk '{print $5}' | tr -d '%'
}
get-icon() {
local icon
local new_vol=${1:-$(get-volume)}
if [[ $(check-muted) == 'Muted' ]]; then
icon="$dev_icon-muted"
else
if ((new_vol < ((MAX * 33) / 100))); then
icon="$dev_icon-low"
elif ((new_vol < ((MAX * 66) / 100))); then
icon="$dev_icon-medium"
else
icon="$dev_icon-high"
fi
fi
echo "$icon"
}
toggle-mute() {
pactl "set-$dev_mute" "$dev" toggle
notify-send "$title: $(check-muted)" -i "$(get-icon)" -r 2425
}
set-volume() {
local vol
vol=$(get-volume)
local new_vol
case $action in
'raise')
new_vol=$((vol + value))
((new_vol > MAX)) && new_vol=$MAX
;;
'lower')
new_vol=$((vol - value))
((new_vol < MIN)) && new_vol=$MIN
;;
esac
pactl "set-$dev_vol" "$dev" "${new_vol}%"
local icon
icon=$(get-icon "$new_vol")
notify-send "$title: ${new_vol}%" -h int:value:$new_vol -i "$icon" -r 2425
}
main() {
device=$1
action=$2
value=${3:-$VALUE}
! ((value > 0)) && print-usage
case $device in
'input')
dev='@DEFAULT_SOURCE@'
dev_mute='source-mute'
dev_vol='source-volume'
dev_icon='mic-volume'
title='Microphone'
;;
'output')
dev='@DEFAULT_SINK@'
dev_mute='sink-mute'
dev_vol='sink-volume'
dev_icon='audio-volume'
title='Volume'
;;
*) print-usage ;;
esac
case $action in
'mute') toggle-mute ;;
'raise' | 'lower') set-volume ;;
*) print-usage ;;
esac
}
main "$@"