Skip to content

Instantly share code, notes, and snippets.

@dux
Created February 18, 2026 10:38
Show Gist options
  • Select an option

  • Save dux/fdb8aebc91125ce5c2370a6729ff773d to your computer and use it in GitHub Desktop.

Select an option

Save dux/fdb8aebc91125ce5c2370a6729ff773d to your computer and use it in GitHub Desktop.
share - zip and upload files/folders to a public URL (gofile, tmpfiles, uguu)
#!/bin/sh
set -e
# share - zip and upload files/folders to a public URL
#
# Usage:
# share file.txt # upload file (via gofile)
# share . # zip current folder, upload
# share folder/ # zip folder, upload
# share uguu file.txt # upload via uguu.se
# share tmpfiles . # zip and upload via tmpfiles.org
#
# Services:
# gofile - no size limit, keeps files (default)
# tmpfiles - temporary hosting, direct download link
# uguu - temporary (1h-24h), direct download link
SERVICES="gofile tmpfiles uguu"
SERVICE="gofile"
CLEANUP=""
die() { printf "error: %s\n" "$1" >&2; exit 1; }
info() { printf ":: %s\n" "$1" >&2; }
cleanup() { [ -n "$CLEANUP" ] && rm -f "$CLEANUP"; }
trap cleanup EXIT
usage() {
sed -n '3,17p' "$0" | sed -E 's/^# ?//'
exit 1
}
is_service() {
for s in $SERVICES; do [ "$1" = "$s" ] && return 0; done
return 1
}
# --- args ---
[ $# -eq 0 ] && usage
if [ $# -ge 2 ] && is_service "$1"; then
SERVICE="$1"
shift
fi
# --- prepare file to upload ---
prepare() {
if [ $# -eq 1 ] && [ -f "$1" ]; then
UPLOAD_FILE="$1"
UPLOAD_NAME="$(basename "$1")"
else
if [ $# -eq 1 ] && [ "$1" = "." ]; then
ZIPNAME="$(basename "$(pwd)")"
elif [ $# -eq 1 ]; then
ZIPNAME="$(basename "$1")"
else
ZIPNAME="archive"
fi
TMPZIP="/tmp/share-${ZIPNAME}-$$.zip"
CLEANUP="$TMPZIP"
info "zipping -> /tmp/${ZIPNAME}.zip"
zip -r -q "$TMPZIP" "$@"
UPLOAD_FILE="$TMPZIP"
UPLOAD_NAME="${ZIPNAME}.zip"
fi
}
# --- upload backends ---
upload_gofile() {
info "uploading to gofile.io ..."
RESP=$(curl -sSf -F "file=@${UPLOAD_FILE};filename=${UPLOAD_NAME}" https://store1.gofile.io/contents/uploadfile)
echo "$RESP" | grep -o '"downloadPage":"[^"]*"' | cut -d'"' -f4
}
upload_tmpfiles() {
info "uploading to tmpfiles.org ..."
RESP=$(curl -sSf -F "file=@${UPLOAD_FILE};filename=${UPLOAD_NAME}" https://tmpfiles.org/api/v1/upload)
RAW=$(echo "$RESP" | grep -o '"url":"[^"]*"' | cut -d'"' -f4)
echo "$RAW" | sed 's|tmpfiles.org/|tmpfiles.org/dl/|'
}
upload_uguu() {
info "uploading to uguu.se ..."
RESP=$(curl -sSf -F "files[]=@${UPLOAD_FILE};filename=${UPLOAD_NAME}" -F "time=24h" https://uguu.se/upload)
echo "$RESP" | tr -d '\n ' | grep -o '"url":"[^"]*"' | cut -d'"' -f4 | sed 's|\\\/|/|g'
}
# --- main ---
prepare "$@"
FILESIZE=$(wc -c < "$UPLOAD_FILE" | tr -d ' ')
info "size: $(echo "$FILESIZE" | awk '{
if ($1 >= 1073741824) printf "%.1f GB", $1/1073741824
else if ($1 >= 1048576) printf "%.1f MB", $1/1048576
else if ($1 >= 1024) printf "%.1f KB", $1/1024
else printf "%d B", $1
}')"
case "$SERVICE" in
gofile) URL=$(upload_gofile) ;;
tmpfiles) URL=$(upload_tmpfiles) ;;
uguu) URL=$(upload_uguu) ;;
esac
[ -z "$URL" ] && die "upload failed — no URL returned"
# copy to clipboard (macOS pbcopy, Linux xclip/xsel)
if command -v pbcopy >/dev/null 2>&1; then
printf "%s" "$URL" | pbcopy
info "copied to clipboard"
elif command -v xclip >/dev/null 2>&1; then
printf "%s" "$URL" | xclip -selection clipboard
info "copied to clipboard"
elif command -v xsel >/dev/null 2>&1; then
printf "%s" "$URL" | xsel --clipboard
info "copied to clipboard"
fi
printf "\n%s\n" "$URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment