Skip to content

Instantly share code, notes, and snippets.

@KSXGitHub
Created August 29, 2022 16:26
Show Gist options
  • Save KSXGitHub/6e9f8690d1b160f39629d973a6b5e858 to your computer and use it in GitHub Desktop.
Save KSXGitHub/6e9f8690d1b160f39629d973a6b5e858 to your computer and use it in GitHub Desktop.
~/.local/share/nautilus/scripts/Share
#!/bin/bash
set -o errexit -o pipefail -o nounset
if [[ "${TERMINAL_OPENED:-false}" == 'false' ]]; then
exec gnome-terminal -- env TERMINAL_OPENED=true "$0" "$@"
fi
storage=$(mktemp -d)
echo "🛈 Created $storage" >&2
for file in "$@"; do
file_path=$(realpath "$file")
echo "🛈 Creating link to $file_path in $storage"
ln -s "$file_path" "$storage" >&2
done
miniserve_flags=(
--dirs-first
--hidden
--show-symlink-info
--qrcode
--verbose
)
server_status=0
echo "🛈 Starting server at $storage" >&2
miniserve "${miniserve_flags[@]}" "$storage" || {
server_status=$?
echo "⮾ Server exit with error (code $server_status)" >&2
}
rm -rfv "$storage" || {
echo "⚠ Failed to clean up (code $?)" >&2
:
}
exit "$server_status"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment