1
0
mirror of https://github.com/eoli3n/dotfiles synced 2024-11-22 23:12:32 +01:00

updated up

This commit is contained in:
eoli3n 2020-11-15 20:50:39 +01:00
parent 9ac86921cf
commit de3f43bf4d

@ -13,18 +13,21 @@
# Vars
autocopy=1
AUTOCOPY=1
# Functions
function usage(){
echo -e "\nBash file uploader\n"
echo -e "Usage :"
echo -e "\t$0 [OPTIONS] file"
echo -e "\tcat file.ext | $0 [OPTIONS]"
echo -e "Options :"
echo -e "\t-h\t Print this usage"
echo -e "\t-a\t Disable autocopy in clipboard"
filename=$(basename "$0")
cat <<- EOF
Bash file uploader
Usage :
"$filename" [OPTIONS] file
cat file.ext | "$filename" [OPTIONS]
Options :
-h Print this usage
-a Disable autocopy in clipboard
EOF
}
function x0(){
@ -48,11 +51,12 @@ function ix(){
# Arguments
while getopts "ha" arg
do
function arguments(){
while getopts "ha" arg
do
case $arg in
a)
autocopy=0
AUTOCOPY=0
;;
h)
usage
@ -63,21 +67,52 @@ do
exit 1
;;
esac
done
shift $((OPTIND-1))
done
shift $((OPTIND-1))
}
# Main
function autocopy(){
# If xorg or wayland is running
if grep 'DISPLAY' <(env) &> /dev/null
then
# If xclip is installed
if which xclip &> /dev/null
then
xclip "$1"
# Else if wl-clipboard is installed
elif which wl-copy &> /dev/null
then
wl-copy "$1"
fi
fi
}
# Test if first argument is an existing file
if [ -n "$1" ] && [ ! -f "$1" ]
then
function is_file(){
# Test if first argument is an existing file
if [ ! -f "$1" ]
then
echo "File \"$1\" not found"
exit 1
fi
fi
}
# If no piped data
if [ -t 0 ]
then
function main(){
# Vars
local url
# Getopts
arguments
# Tests
if [ -n "$1" ]
then
is_file "$1"
fi
# If no piped data
if [ -t 0 ]
then
# If no argument, read stdin and save url
if [ -z "$1" ]
@ -90,29 +125,23 @@ then
url=$(x0 "$1")
fi
# Else if piped data
else
# Else if piped data
else
# Upload to ix.io and save url
url=$(ix)
fi
# Print url
echo "$url"
# If autocopy is set
if [ "$autocopy" == "1" ]
then
# If xorg or wayland is running
if env | grep 'DISPLAY' &> /dev/null
then
# If xclip is installed
if which xclip &> /dev/null
then
xclip "$url"
# Else if wl-clipboard is installed
elif which wl-copy &> /dev/null
then
wl-copy "$url"
fi
# Print url
echo "$url"
# If autocopy is set
if [ "$AUTOCOPY" == "1" ]
then
# Autocopy url
autocopy "$url"
fi
fi
}
# Main
main "$1"