aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/.local/bin/scripts/grimpick62
-rwxr-xr-xbin/.local/bin/scripts/ww-tag.sh23
-rwxr-xr-xbin/.local/bin/scripts/ww.sh38
-rwxr-xr-xbin/.local/bin/scripts/xwayland-launch36
4 files changed, 159 insertions, 0 deletions
diff --git a/bin/.local/bin/scripts/grimpick b/bin/.local/bin/scripts/grimpick
new file mode 100755
index 0000000..0c12409
--- /dev/null
+++ b/bin/.local/bin/scripts/grimpick
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# Ensure directory exists
+mkdir -p "$HOME/Pictures/screenshots"
+
+# Variables
+TIMESTAMP=$(date '+%y%m%d-%H%M-%S')
+DIR="$HOME/Pictures/screenshots"
+CLIP_CMD="wl-copy -t image/png"
+
+# Use fuzzel as a modern dmenu replacement (fallback to standard dmenu if running via XWayland,
+# but fuzzel/rofi-wayland is highly recommended for Wayland native surface scaling)
+MENU_CMD="fuzzel --dmenu -p"
+
+# 1. Main menu prompt
+selection=$(printf "a selected area\ncurrent window\nfull screen\na selected area (copy)\ncurrent window (copy)\nfull screen (copy)" | $MENU_CMD "Screenshot which area?")
+
+[ -z "$selection" ] && exit 0
+
+# Helper function to get active window geometry from niri
+get_active_window_geom() {
+ # Fetches active window info via Niri IPC and formats it for grim (-g)
+ niri msg --json outputs | jq -r '.[] | .focused_window | select(. != null) | "\(.position.x),\(.position.y) \(.size.width)x\(.size.height)"'
+}
+
+# 2. Execution Logic
+case "$selection" in
+ "a selected area")
+ GEOM=$(slurp)
+ [ -n "$GEOM" ] && grim -g "$GEOM" "$DIR/pic-selected-${TIMESTAMP}.png"
+ ;;
+ "current window")
+ GEOM=$(get_active_window_geom)
+ if [ -n "$GEOM" ]; then
+ grim -g "$GEOM" "$DIR/pic-window-${TIMESTAMP}.png"
+ else
+ # Fallback to manual selection if no window is focused
+ grim -g "$(slurp)" "$DIR/pic-window-${TIMESTAMP}.png"
+ fi
+ ;;
+ "full screen")
+ # Slurp -o lets you click a specific monitor, or press Escape/Click outside to cancel
+ GEOM=$(slurp -p -o)
+ [ -n "$GEOM" ] && grim -g "$GEOM" "$DIR/pic-full-${TIMESTAMP}.png"
+ ;;
+ "a selected area (copy)")
+ GEOM=$(slurp)
+ [ -n "$GEOM" ] && grim -g "$GEOM" - | $CLIP_CMD
+ ;;
+ "current window (copy)")
+ GEOM=$(get_active_window_geom)
+ if [ -n "$GEOM" ]; then
+ grim -g "$GEOM" - | $CLIP_CMD
+ else
+ grim -g "$(slurp)" - | $CLIP_CMD
+ fi
+ ;;
+ "full screen (copy)")
+ GEOM=$(slurp -p -o)
+ [ -n "$GEOM" ] && grim -g "$GEOM" - | $CLIP_CMD
+ ;;
+esac
diff --git a/bin/.local/bin/scripts/ww-tag.sh b/bin/.local/bin/scripts/ww-tag.sh
new file mode 100755
index 0000000..305937d
--- /dev/null
+++ b/bin/.local/bin/scripts/ww-tag.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+
+WALLPAPER_DIR="$HOME/Pictures/wallpaper"
+
+if [[ ! -d "$WALLPAPER_DIR" ]]; then
+ echo "$WALLPAPER_DIR does not exist"
+ exit 1
+fi
+
+# Extract all unique tags from filenames
+selected_tag=$(find "$WALLPAPER_DIR" -type f -print0 \
+ | xargs -0 -n1 bash -c 'grep -oP "\[\K[^\]]+" <<< "$0" | tr "," "\n"' \
+ | sed 's/^ *//;s/ *$//' \
+ | sort -u \
+ | fuzzel --dmenu -p "Select tag: ")
+[ -z "$selected_tag" ] && exit 1
+
+# Find wallpapers matching the tag, pick one via nsxiv thumbnail view
+selected_wallpaper=$(find "$WALLPAPER_DIR" -type f -regex ".*\[[^]]*${selected_tag}[^]]*\].*" -print0 \
+ | xargs -0 nsxiv -t -o)
+[ -z "$selected_wallpaper" ] && exit 1
+
+awww img "$selected_wallpaper"
diff --git a/bin/.local/bin/scripts/ww.sh b/bin/.local/bin/scripts/ww.sh
new file mode 100755
index 0000000..9f3bd76
--- /dev/null
+++ b/bin/.local/bin/scripts/ww.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env bash
+
+# Exit on error
+set -e
+
+# Path to the directory containing your wallpapers
+WALLPAPER_DIRS="$HOME/Pictures/wallpaper
+$HOME/Pictures/other-wallpaper"
+
+# Modern Wayland dmenu replacement
+MENU_CMD="fuzzel --dmenu -p"
+
+# If image is passed as argument, skip selection
+if [ -n "$1" ]; then
+ selected_wallpaper="$1"
+
+ # Expand ~ and get absolute path
+ selected_wallpaper="$(realpath "$selected_wallpaper")"
+
+ if [ ! -f "$selected_wallpaper" ]; then
+ echo "Error: File does not exist: $selected_wallpaper"
+ exit 1
+ fi
+else
+ # Use Wayland menu to select directory
+ WALLPAPER_DIR=$(printf "%s\n" "$WALLPAPER_DIRS" | $MENU_CMD "Select directory:")
+
+ [ -z "$WALLPAPER_DIR" ] && exit 1
+
+ # nsxiv picker
+ selected_wallpaper=$(xwayland-launch nsxiv -t -r -o "$WALLPAPER_DIR")
+
+ [ -z "$selected_wallpaper" ] && exit 1
+fi
+
+awww img "$selected_wallpaper"
+
+echo "Wallpaper set successfully via awww."
diff --git a/bin/.local/bin/scripts/xwayland-launch b/bin/.local/bin/scripts/xwayland-launch
new file mode 100755
index 0000000..d257f3c
--- /dev/null
+++ b/bin/.local/bin/scripts/xwayland-launch
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+# Exit early if no command was passed
+if [ -z "$1" ]; then
+ echo "Usage: $0 <command> [arguments]"
+ exit 1
+fi
+
+# Ensure a DISPLAY environment variable is set if missing
+if [ -z "$DISPLAY" ]; then
+ export DISPLAY=:0
+ xrdb -merge ~/.Xresources
+ xrdb -merge ~/.Xresources.d/Xresources.vivendi
+fi
+
+# Check if an X11 server is already responding on this display
+if ! xset q >/dev/null 2>&1; then
+ echo "XWayland not running. Launching xwayland-satellite..."
+ # Start xwayland-satellite in the background
+ xwayland-satellite :0 &
+ SATELLITE_PID=$!
+ # Wait for the X11 server to actually become responsive
+ timeout=5
+ while ! xset q >/dev/null 2>&1; do
+ sleep 0.1
+ timeout=$((timeout - 1))
+ if [ "$timeout" -le 0 ]; then
+ echo "Error: xwayland-satellite failed to start in time."
+ kill "$SATELLITE_PID" 2>/dev/null
+ exit 1
+ fi
+ done
+fi
+
+# Execute the application with all passed arguments
+exec "$@"