#!/bin/bash
##Ledmitz (2023)
##Public Domain
CURLCHECK=$(which curl)
if [[ "$CURLCHECK" == '' ]]; then
echo 'curl must be installed to use 7hs-up'
exit 0
fi
if [[ "$1" == '-h' ]] || [[ "$1" == '--help' ]] || [[ "$1" == 'help' ]] || [[ "$1" == '' ]]; then
echo 'Usage: 7hs-up [FILE]'
echo 'Uploads FILE to 7hs.com. Output is the URL to the FILE.'
echo -e '\nIf xclip is installed, click the mouse wheel(on most systems) to paste\n'
echo -e '\t7hs-up -h, --help, help'
exit 0
fi
UPFILE="$1"
UPFILE_NAME=$(basename "$UPFILE")
DOWNLINK=$(curl -s -T "$UPFILE" 'https://7hs.com/upload/' "https://7hs.com/$UPFILE_NAME" 2> '/dev/null' | head -n 1 | grep '^http')
if [[ "$DOWNLINK" == '' ]]; then
if [ ! -f "$UPFILE" ]; then
echo 'Non-existant file'
else
echo 'Network error'
fi
else
XCLIPCHECK=$(which xclip)
if [[ "$XCLIPCHECK" == '' ]]; then
echo "$DOWNLINK"
else
echo "$DOWNLINK" | xclip -r
echo "Copied to clipboard(mousewheel): $DOWNLINK"
fi
fi