others/share.sh

50 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
## upload files and share with transfer.sh in non-X sessions ##
# share.sh by @root_informatica.
# menu variable depending on the environment
[ -t 0 ] && MENU="fzy" \
|| MENU="xmenu.sh"
# options
OPT=$(echo -e "documentos\nimágenes\nmúsica\nscripts\nvídeos" | $MENU)
# define filters
case $OPT in
documentos)
filter=".pdf|.txt"
;;
imágenes)
filter=".png|.jpg|.jpeg|.xbm"
;;
música)
filter=".mp3|.flac|.wav|.ogg|.webm"
;;
scripts)
filter=".pl|.py|.sh|.bash"
;;
vídeos)
filter=".mp4|.avi|.mkv"
;;
esac
# if filter.
if [ -n "$filter" ]; then
# path to file.
filepath=$(find $HOME -type f | grep -E "$filter" | $MENU)
# if filepath.
if [ -n "$filepath" ]; then
# if display.
if [ -n "$DISPLAY" ]; then
# upload the file and save the path in the clipboard
curl -F "file=@$filepath" -F "secret=" https://0x0.st | xclip
# make it available to other programs
xclip -o | xclip -sel c
else
# upload the file and save the path in /tmp
curl -F "file=@$filepath" -F "secret=" https://0x0.st > /tmp/share.txt
fi
fi
fi