# Custom utility scripts { config, lib, pkgs, nomarchyConfig, ... }: let homeDir = "/home/${nomarchyConfig.username}"; in { # Screenshot region script home.file.".local/bin/screenshot-region" = { executable = true; text = '' #!/usr/bin/env bash grim -g "$(slurp)" - | satty -f - ''; }; # Screenshot active window script home.file.".local/bin/screenshot-window" = { executable = true; text = '' #!/usr/bin/env bash GEOM=$(hyprctl activewindow -j | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"') grim -g "$GEOM" - | satty -f - ''; }; # Screen recording toggle script home.file.".local/bin/screen-record" = { executable = true; text = '' #!/usr/bin/env bash PIDFILE="/tmp/wf-recorder.pid" STATUSFILE="/tmp/recording-status" OUTDIR="$HOME/Videos/Recordings" mkdir -p "$OUTDIR" if [ -f "$PIDFILE" ]; then kill -INT "$(cat $PIDFILE)" 2>/dev/null rm -f "$PIDFILE" "$STATUSFILE" notify-send -u normal "Recording Saved" "$(ls -t $OUTDIR/*.mp4 2>/dev/null | head -1)" else FILENAME="$OUTDIR/recording_$(date +%Y%m%d_%H%M%S).mp4" CHOICE=$(echo -e "󰍹 Region\n󰹑 Fullscreen" | rofi -dmenu -p "Record") case "$CHOICE" in *"Region"*) GEOM=$(slurp) [ -z "$GEOM" ] && exit 1 wf-recorder -g "$GEOM" -f "$FILENAME" & ;; *"Fullscreen"*) wf-recorder -f "$FILENAME" & ;; *) exit 1 ;; esac echo $! > "$PIDFILE" echo "recording" > "$STATUSFILE" notify-send -u critical "Recording" "Click waybar or Super+/ to stop" fi ''; }; # Quick Actions menu home.file.".local/bin/quick-actions" = { executable = true; text = '' #!/usr/bin/env bash ACTION=$(cat << 'EOF' | rofi -dmenu -i -p "" 󰍹 Screenshot Region 󰹑 Screenshot Window 󰕧 Record Screen 󰆏 Clipboard History 󰖩 Share WiFi (QR Code) 󱂵 Change Wallpaper 󰈈 Color Picker 󰂜 Notifications System Settings 󰌌 Keybindings 󰗼 Lock 󰍃 Logout 󰜉 Reboot 󰐥 Shutdown EOF ) case "$ACTION" in *"Screenshot Region"*) ~/.local/bin/screenshot-region ;; *"Screenshot Window"*) ~/.local/bin/screenshot-window ;; *"Record Screen"*) ~/.local/bin/screen-record ;; *"Clipboard History"*) cliphist list | rofi -dmenu -p '󰆏' | cliphist decode | wl-copy ;; *"Share WiFi"*) ~/.local/bin/wifi-share ;; *"Change Wallpaper"*) ~/.local/bin/wallpaper-rotate && notify-send "Wallpaper changed" ;; *"Color Picker"*) hyprpicker -a && notify-send "Color copied to clipboard" ;; *"Notifications"*) swaync-client -t -sw ;; *"System Settings"*) ~/.local/bin/system-settings ;; *"Keybindings"*) ~/.local/bin/keybindings-help ;; *"Lock"*) hyprlock ;; *"Logout"*) hyprctl dispatch exit ;; *"Reboot"*) systemctl reboot ;; *"Shutdown"*) systemctl poweroff ;; esac ''; }; # Keybindings help home.file.".local/bin/keybindings-help" = { executable = true; text = '' #!/usr/bin/env bash cat << 'EOF' | rofi -dmenu -i -p "Keybindings (Super+)" -theme-str 'window {width: 400px;} listview {lines: 16;}' Q Terminal R App Launcher E File Manager B Browser W Close Window F Fullscreen V Float/Tile Arrows Move Focus 1-9 Workspace / Quick Actions A Notifications Space Switch Layout EOF ''; }; # Power menu home.file.".local/bin/power-menu" = { executable = true; text = '' #!/usr/bin/env bash ACTION=$(echo -e "󰗼 Lock\n󰍃 Logout\n󰜉 Reboot\n󰐥 Shutdown" | rofi -dmenu -i -p "") case "$ACTION" in *"Lock"*) hyprlock ;; *"Logout"*) hyprctl dispatch exit ;; *"Reboot"*) systemctl reboot ;; *"Shutdown"*) systemctl poweroff ;; esac ''; }; # WiFi sharing with QR code home.file.".local/bin/wifi-share" = { executable = true; text = '' #!/usr/bin/env bash SSID=$(nmcli -t -f active,ssid dev wifi | grep '^yes' | cut -d: -f2) if [ -z "$SSID" ]; then notify-send "WiFi Share" "Not connected to WiFi" exit 1 fi PASSWORD=$(nmcli -s -g 802-11-wireless-security.psk connection show "$SSID" 2>/dev/null) if [ -z "$PASSWORD" ]; then notify-send "WiFi Share" "Could not retrieve password" exit 1 fi WIFI_STRING="WIFI:T:WPA;S:$SSID;P:$PASSWORD;;" QR_FILE="/tmp/wifi-qr.png" qrencode -o "$QR_FILE" -s 10 "$WIFI_STRING" ACTION=$(echo -e "󰐲 View QR Code\n󰆏 Copy Password\n󰖩 Copy SSID" | rofi -dmenu -i -p "󰖩 $SSID") case "$ACTION" in *"View QR"*) if command -v imv &> /dev/null; then imv "$QR_FILE" & else xdg-open "$QR_FILE" & fi notify-send "WiFi QR Code" "Scan to connect to $SSID" ;; *"Copy Password"*) echo -n "$PASSWORD" | wl-copy notify-send "Password Copied" "$SSID password copied to clipboard" ;; *"Copy SSID"*) echo -n "$SSID" | wl-copy notify-send "SSID Copied" "$SSID copied to clipboard" ;; esac ''; }; # System settings menu home.file.".local/bin/system-settings" = { executable = true; text = '' #!/usr/bin/env bash ACTION=$(cat << 'EOF' | rofi -dmenu -i -p "" 󰖩 WiFi Settings 󰂯 Bluetooth 󰕾 Sound Settings 󰃟 Display Settings NixOS Generations 󰚰 Update System 󰃨 Garbage Collect EOF ) case "$ACTION" in *"WiFi"*) nm-connection-editor ;; *"Bluetooth"*) blueman-manager 2>/dev/null || notify-send "Bluetooth" "blueman not installed" ;; *"Sound"*) pavucontrol 2>/dev/null || notify-send "Sound" "pavucontrol not installed" ;; *"Display"*) wdisplays 2>/dev/null || notify-send "Display" "wdisplays not installed" ;; *"Generations"*) ghostty -e bash -c "sudo nix-env --profile /nix/var/nix/profiles/system --list-generations | tail -20; echo; read -p 'Press Enter to close...'" ;; *"Update"*) ghostty -e bash -c "cd ~/.config/nomarchy && nix flake update && sudo nixos-rebuild switch --flake .#; echo; read -p 'Press Enter to close...'" ;; *"Garbage"*) ghostty -e bash -c "sudo nix-collect-garbage -d; echo; read -p 'Press Enter to close...'" ;; esac ''; }; # WiFi menu home.file.".local/bin/wifi-menu" = { executable = true; text = '' #!/usr/bin/env bash CURRENT=$(nmcli -t -f active,ssid dev wifi | grep '^yes' | cut -d: -f2) MENU="󰖩 Scan for networks\n" if [ -n "$CURRENT" ]; then MENU+="󰐲 Share WiFi (QR Code)\n" MENU+="󰖪 Disconnect ($CURRENT)\n" fi MENU+="󰤨 Toggle WiFi\n" MENU+="───────────────\n" NETWORKS=$(nmcli -t -f ssid,signal,security dev wifi list | grep -v '^$' | head -10) while IFS=: read -r ssid signal security; do if [ -n "$ssid" ]; then if [ "$ssid" = "$CURRENT" ]; then MENU+="󰤨 $ssid ($signal%) ✓\n" elif [ -n "$security" ]; then MENU+="󰤡 $ssid ($signal%)\n" else MENU+="󰤨 $ssid ($signal%)\n" fi fi done <<< "$NETWORKS" CHOICE=$(echo -e "$MENU" | rofi -dmenu -i -p "󰖩" | sed 's/^[^ ]* *//' | sed 's/ ([0-9]*%).*$//' | sed 's/ ✓$//') case "$CHOICE" in "Scan for networks") notify-send "WiFi" "Scanning..." nmcli dev wifi rescan sleep 2 ~/.local/bin/wifi-menu ;; "Share WiFi"*) ~/.local/bin/wifi-share ;; "Disconnect"*) nmcli dev disconnect wlan0 notify-send "WiFi" "Disconnected" ;; "Toggle WiFi") if nmcli radio wifi | grep -q "enabled"; then nmcli radio wifi off notify-send "WiFi" "Disabled" else nmcli radio wifi on notify-send "WiFi" "Enabled" fi ;; "─"*) ;; "") ;; *) if nmcli -t -f name connection show | grep -q "^$CHOICE$"; then nmcli connection up "$CHOICE" && notify-send "WiFi" "Connected to $CHOICE" else PASS=$(rofi -dmenu -p "Password for $CHOICE" -password) if [ -n "$PASS" ]; then nmcli dev wifi connect "$CHOICE" password "$PASS" && notify-send "WiFi" "Connected to $CHOICE" fi fi ;; esac ''; }; # Bluetooth toggle home.file.".local/bin/bluetooth-toggle" = { executable = true; text = '' #!/usr/bin/env bash if bluetoothctl show | grep -q "Powered: yes"; then bluetoothctl power off notify-send "Bluetooth" "Disabled" else bluetoothctl power on notify-send "Bluetooth" "Enabled" fi ''; }; # Wallpaper rotation script home.file.".local/bin/wallpaper-rotate" = { executable = true; text = '' #!/usr/bin/env bash WALLPAPER_DIR="${homeDir}/.config/nomarchy/wallpapers" MONITOR="eDP-1" if [ -z "$HYPRLAND_INSTANCE_SIGNATURE" ]; then XDG_RUNTIME_DIR="''${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" HYPRLAND_INSTANCE_SIGNATURE="$(ls "$XDG_RUNTIME_DIR/hypr/" 2>/dev/null | head -1)" fi export HYPRLAND_INSTANCE_SIGNATURE if [ -z "$HYPRLAND_INSTANCE_SIGNATURE" ]; then echo "No Hyprland instance found" exit 1 fi WALLPAPER=$(find "$WALLPAPER_DIR" -type f \( -name "*.jpg" -o -name "*.png" \) | shuf -n 1) if [ -n "$WALLPAPER" ]; then hyprctl hyprpaper wallpaper "$MONITOR,$WALLPAPER" fi ''; }; }