update
This commit is contained in:
@@ -11,7 +11,14 @@ cleanup() {
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
choose_subfolder() {
|
||||
trim_whitespace() {
|
||||
local value="$1"
|
||||
value="${value#"${value%%[![:space:]]*}"}"
|
||||
value="${value%"${value##*[![:space:]]}"}"
|
||||
printf '%s\n' "$value"
|
||||
}
|
||||
|
||||
choose_destination_dir() {
|
||||
if [[ ! -d "$base_dir" ]] || ! mountpoint -q /mnt/data; then
|
||||
return 1
|
||||
fi
|
||||
@@ -21,7 +28,7 @@ choose_subfolder() {
|
||||
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 selected=$(wofi --dmenu --prompt 'Save screenshot path' < "$selection_file"); then
|
||||
if [[ -z "$selected" || "$selected" == "/" ]]; then
|
||||
printf '%s\n' "$base_dir"
|
||||
else
|
||||
@@ -33,6 +40,47 @@ choose_subfolder() {
|
||||
printf '%s\n' "$base_dir"
|
||||
}
|
||||
|
||||
choose_filename() {
|
||||
local default_name="screenshot"
|
||||
local selected=""
|
||||
|
||||
if selected=$(printf '%s\n' "$default_name" | wofi --dmenu --prompt 'Save screenshot filename'); then
|
||||
selected=$(trim_whitespace "$selected")
|
||||
else
|
||||
selected="$default_name"
|
||||
fi
|
||||
|
||||
if [[ -z "$selected" ]]; then
|
||||
selected="$default_name"
|
||||
fi
|
||||
|
||||
selected="${selected%.png}"
|
||||
|
||||
if [[ -z "$selected" ]]; then
|
||||
selected="$default_name"
|
||||
fi
|
||||
|
||||
printf '%s\n' "$selected"
|
||||
}
|
||||
|
||||
build_unique_path() {
|
||||
local destination_dir="$1"
|
||||
local file_stem="$2"
|
||||
local candidate="$destination_dir/$file_stem.png"
|
||||
local counter=1
|
||||
|
||||
if [[ ! -e "$candidate" ]]; then
|
||||
printf '%s\n' "$candidate"
|
||||
return
|
||||
fi
|
||||
|
||||
while [[ -e "$destination_dir/$file_stem-$counter.png" ]]; do
|
||||
counter=$((counter + 1))
|
||||
done
|
||||
|
||||
printf '%s\n' "$destination_dir/$file_stem-$counter.png"
|
||||
}
|
||||
|
||||
if ! region="$(slurp)"; then
|
||||
exit 0
|
||||
fi
|
||||
@@ -43,11 +91,13 @@ fi
|
||||
|
||||
wl-copy --type image/png < "$tmp_file"
|
||||
|
||||
if destination_dir="$(choose_subfolder)"; then
|
||||
if destination_dir="$(choose_destination_dir)"; 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"
|
||||
file_stem="$(choose_filename)"
|
||||
destination_path="$(build_unique_path "$destination_dir" "$file_stem")"
|
||||
cp "$tmp_file" "$destination_path"
|
||||
notify-send 'Screenshot saved' "$destination_path
|
||||
Copied to clipboard"
|
||||
else
|
||||
notify-send 'Screenshot copied' 'NAS picture share is not available; image copied to clipboard only'
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user