Skip to content

Instantly share code, notes, and snippets.

@nothub
Last active June 21, 2021 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nothub/fac9f54538f4fe9a8ae3ec44f22ca31e to your computer and use it in GitHub Desktop.
Save nothub/fac9f54538f4fe9a8ae3ec44f22ca31e to your computer and use it in GitHub Desktop.
poor mans screenshot upload
#!/usr/bin/env bash
set -e
SSH_USER=''
SSH_HOST=''
SSH_PATH='' # relative
BASE_URL='' # http
LOCAL_ARCHIVE_PATH="$HOME/scrup"
if [ -z "$SSH_USER" ] || [ -z "$SSH_HOST" ] || [ -z "$SSH_PATH" ] || [ -z "$BASE_URL" ]; then
echo "incomplete configuration!" && exit 1
fi
if ! notify-send -v >/dev/null 2>&1 || ! scrot -v >/dev/null 2>&1 || ! xclip -version >/dev/null 2>&1; then
echo "required dependencies: notify-send, scrot, xclip" && exit 1
fi
mkdir -p "$LOCAL_ARCHIVE_PATH"
cd "$LOCAL_ARCHIVE_PATH"
sleep 0.1 && scrot -s --line=style=dash,width=1 -f
# shellcheck disable=SC2012
FILE_LOCAL=$(ls -Art | tail -n 1)
xclip -selection clipboard -target image/png -i "$FILE_LOCAL"
FILE_REMOTE="$(tr </dev/urandom -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1).png"
scp "$FILE_LOCAL" "$SSH_USER"@"$SSH_HOST":"$SSH_PATH"/"$FILE_REMOTE"
FILE_URL="$BASE_URL/$FILE_REMOTE"
printf '%s\n' "$(date +%s)" "$FILE_LOCAL" "$FILE_URL" | paste -sd ',' >>log.csv
echo "$FILE_URL" | xclip -selection clipboard
notify-send -t 2000 "scrup" "$FILE_URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment