forked from tcp.direct/tcp.ac
1
0
Fork 0

added dmenu intergration uploader script

This commit is contained in:
sad 2022-04-06 09:28:28 -06:00
parent d41ef591e0
commit c18f640595
No known key found for this signature in database
GPG Key ID: 2C1C1331B02E8D1C

54
scripts/uploader-dmenu.sh Normal file
View File

@ -0,0 +1,54 @@
#!/bin/sh
function tcpup {
options="Upload an Image\nRecent Uploads\nCancel"
selected=$(echo -e $options | dmenu -l 3 )
if [[ "$selected" == "Upload an Image" ]]; then
target="$1"
[ -z "$target" ] && target="$(realpath .)"
ls() {
echo ..
command ls -ALNpX1 --group-directories-first "$target"
}
while :; do
sel="$(ls | dmenu -l 25)" || exit
if [ "$(echo "$sel")" = "/" ]; then
newt="$sel"
else
newt="$(realpath "$target/$sel")"
fi
if [ -e "$newt" ]; then
target="$newt"
if [ ! -d "$target" ]; then
echo "Location: $target"
command="curl -s -F'upload=@$target' https://tcp.ac/i/put"
echo "Uploading: $target"
url=$(eval $command)
echo "URL: $url"
CLEAN=$(echo $url | sed 's|\\||g' | sed 's|"{"|{"|g' | sed 's|"}"|"}|g')
IMGURL=$(echo $CLEAN | awk -F ':' '{print $2 $3}' | awk -F ',' '{print $1}' | awk -F '}' '{print $1}' | sed -e 's|"||g' -e 's|"||g' -e 's|https|https:|g' -e 's|http\/\/|http:\/\/|g')
echo -n $IMGURL | xclip -sel clip
notify-send "File Uploaded" "URL: $IMGURL \ncopied to clipboard" -t 5000
entry="$(date '+%d-%m-%y-%H:%M:%S') $url $(echo $target | awk -F'/' '{print $(NF)}')"
echo $entry >> $HOME/.tcp-uploads
echo "Uploaded"; break
fi
fi
done
elif [[ "$selected" == "Recent Uploads" ]]; then
var=$(tac ~/.tcp-uploads | dmenu -l 10)
filename=$(echo $var | awk '{print $3}')
url=$(echo $var | awk '{print $2}')
printf "$url" | xclip -sel clip
notify-send "$filename" "URL: $IMGURL \ncopied to clipboard" -t 5000
elif [[ "$selected" == "Cancel" ]]; then
return
fi
}
tcpup