#!/bin/sh # For theme to be applied ~/.Xresource file must be present set -f while read -r file; do case "$1" in "m") # FIXME: Providing directory selections to dmenu limits choices; # e.g., if `/home/user/pics` is given, `/` can't be selected. if [ -z "${destdir}" ]; then destdir="$(printf '' \ | dmenu -c -bw 2 -p "Copy directory: " \ | sed "s|~|${HOME}|g")" fi # Skip non-directories to prevent overwriting files during loop processing if [ ! -d "${destdir}" ]; then nsend -s "Failed to move" "Not a directory: ${destdir}" exit 1 fi if output=$(mv -- "${file}" "${destdir}" 2>&1); then nsend -s "Moved" "${file} to ${destdir}" & else nsend -s "Failed to Move" "$output" & fi ;; "c") if [ -z "${destdir}" ]; then destdir="$(printf '' \ | dmenu -c -bw 2 -p "Copy directory: " \ | sed "s|~|${HOME}|g")" fi if [ ! -d "${destdir}" ]; then nsend -s "Failed to copy" "Not a directory: ${destdir}" exit 1 fi if output=$(cp -- "${file}" "${destdir}" 2>&1); then nsend -s "Copied" "${file} to ${destdir}" & else nsend -s "Failed to copy" "$output" & fi ;; "d") mkdir -p "${HOME}/.trash" trash_path="$HOME/.trash/$(basename -- "${file}")" if [ -e "${trash_path}" ]; then rand=$(od -An -N2 -tu2 /dev/urandom | tr -d ' ') trash_path="${trash_path}_$(date +%Y%m%d%H%M%S)_${rand}" fi if output=$(mv -- "${file}" "${trash_path}" 2>&1); then nsend -s "Deleted" "${file} to ${trash_path}" & else nsend -s "Failed to delete" "$output" & fi ;; "y") if printf "%s" "${file}" | xclip -selection clipboard; then nsend -s "Relative path copied to clipboard." & else nsend -s "Failed to copy relative path to clipboard." & fi ;; "Y") if readlink -f "${file}" | tr -d '\n' | xclip -selection clipboard; then nsend -s "Full path copied to clipboard." & else nsend -s "Failed to copy full path to clipboard." & fi ;; "w") if output=$(swall -d "${file}" 2>&1); then nsend -s "Set as wallpaper" "${file}" & else nsend -s "Failed to set as wallpaper" "$output" & fi ;; # No need for nsend since whether the photo has rotated or not is obvious # FIXME: convert is depricated use magick instead "r") convert -rotate 90 "${file}" "${file}" ;; "R") convert -rotate -90 "${file}" "${file}" ;; "f") convert -flop "${file}" "${file}" ;; esac done