54 lines
1.3 KiB
Bash
Executable File
54 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
base_dir="/mnt/data/media/share/pictures"
|
|
tmp_file="$(mktemp --suffix=.png)"
|
|
selection_file="$(mktemp)"
|
|
|
|
cleanup() {
|
|
rm -f "$tmp_file" "$selection_file"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
choose_subfolder() {
|
|
if [[ ! -d "$base_dir" ]] || ! mountpoint -q /mnt/data; then
|
|
return 1
|
|
fi
|
|
|
|
{
|
|
printf '/\n'
|
|
find "$base_dir" -mindepth 1 -type d -printf '%P\n' | sort
|
|
} > "$selection_file"
|
|
|
|
if selected=$(wofi --dmenu --prompt 'Save screenshot folder' < "$selection_file"); then
|
|
if [[ -z "$selected" || "$selected" == "/" ]]; then
|
|
printf '%s\n' "$base_dir"
|
|
else
|
|
printf '%s/%s\n' "$base_dir" "$selected"
|
|
fi
|
|
return 0
|
|
fi
|
|
|
|
printf '%s\n' "$base_dir"
|
|
}
|
|
|
|
if ! region="$(slurp)"; then
|
|
exit 0
|
|
fi
|
|
|
|
if ! grim -g "$region" - | swappy -f - -o "$tmp_file"; then
|
|
exit 1
|
|
fi
|
|
|
|
wl-copy --type image/png < "$tmp_file"
|
|
|
|
if destination_dir="$(choose_subfolder)"; then
|
|
mkdir -p "$destination_dir"
|
|
file_name="screenshot-$(date +%Y%m%d-%H%M%S).png"
|
|
cp "$tmp_file" "$destination_dir/$file_name"
|
|
notify-send 'Screenshot saved' "$destination_dir/$file_name\nCopied to clipboard"
|
|
else
|
|
notify-send 'Screenshot copied' 'NAS picture share is not available; image copied to clipboard only'
|
|
fi
|