Files
omarchycn/bin/omarchy-menu-share
77bf2ef704 Share files and folders with the desktop file chooser (#6707)
Sharing a file or folder over LocalSend opened a terminal to run an fzf
pick over a find of the whole home directory, which is slow on a large
home, shows no previews, and looks nothing like the rest of the desktop.
The portal chooser is already how the other pickers here ask.

The chooser has a directory mode, so folder sharing asks for one the same
way, and neither entry needs a terminal to host a picker anymore.

A chooser that never opens is told apart from nobody picking anything, so
a portal failure says so rather than passing for a cancelled share.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-11 14:24:17 +02:00

51 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# omarchy:summary=Share clipboard, files, or folders with LocalSend
# omarchy:group=share
# omarchy:name=
# omarchy:args=<clipboard|file|folder> [path...]
# omarchy:examples=omarchy share clipboard | omarchy share file ~/Downloads/example.txt
if (($# == 0)); then
echo "Usage: omarchy-menu-share [clipboard|file|folder]"
exit 1
fi
MODE="$1"
shift
if [[ $MODE == "clipboard" ]]; then
TEMP_FILE=$(mktemp --suffix=.txt)
wl-paste >"$TEMP_FILE"
FILE_ARRAY=("$TEMP_FILE")
elif (($# > 0)); then
FILE_ARRAY=("$@")
else
if [[ $MODE == "folder" ]]; then
select_args=(--title "Share folder" --directory)
else
select_args=(--title "Share files" --multiple)
fi
# Command substitution so the chooser's exit status survives: reading it
# through a process substitution reports success for a chooser that never
# opened, which is indistinguishable here from someone deciding not to share.
picked=$(omarchy-file-select "${select_args[@]}") || status=$?
if ((${status:-0} > 1)); then
omarchy-notification-send -g "" -u critical "Could not share" "The file chooser did not open"
exit 1
fi
[[ -n $picked ]] || exit 0
readarray -t FILE_ARRAY <<<"$picked"
fi
# Run LocalSend in its own systemd service (detached from terminal)
systemd-run --user --quiet --collect localsend --headless send "${FILE_ARRAY[@]}"
# Note: Temporary file will remain until system cleanup for clipboard mode
# This ensures the file content is available for the LocalSend GUI
exit 0