2020-03-11 16:08:44 +01:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
|
|
|
|
|
|
|
|
|
|
# This script will try to:
|
|
|
|
|
## Get first argument
|
|
|
|
|
## Or get clipboard content if no argument
|
|
|
|
|
## Send this data to an URL shortener
|
|
|
|
|
## Print the short url to stdout
|
|
|
|
|
## Or put it in the clipboard if no argument was given
|
|
|
|
|
|
|
|
|
|
# Vars [[[
|
|
|
|
|
debug="0"
|
|
|
|
|
flag_clipboard=1
|
|
|
|
|
flag_inline=1
|
|
|
|
|
|
2020-03-11 16:38:05 +01:00
|
|
|
|
null_service_url="https://null.101010.fr"
|
2020-03-11 16:08:44 +01:00
|
|
|
|
|
|
|
|
|
## Colors [[[
|
|
|
|
|
c_redb='\033[1;31m'
|
|
|
|
|
c_magentab='\033[1;35m'
|
|
|
|
|
c_reset='\033[0m'
|
|
|
|
|
## ]]]
|
|
|
|
|
|
|
|
|
|
# ]]]
|
|
|
|
|
|
|
|
|
|
# Verify argument [[[
|
|
|
|
|
case "$#" in
|
|
|
|
|
0 )
|
|
|
|
|
flag_clipboard=0
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG − Verify arg : No argument was given, try to use clipboard."
|
|
|
|
|
;;
|
|
|
|
|
1 )
|
|
|
|
|
flag_inline=0
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG − Verify arg : One argument was given, use it."
|
|
|
|
|
;;
|
|
|
|
|
* )
|
|
|
|
|
printf "${c_redb}%b${c_reset}\n" "Error : Expect one argument or a content in clipboard."
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
# ]]]
|
|
|
|
|
|
2020-03-11 16:36:06 +01:00
|
|
|
|
# Get URL to be shortened [[[
|
|
|
|
|
# Try to get URL from first argument
|
|
|
|
|
if [ ${flag_inline} ]; then
|
|
|
|
|
url_to_short="${1}"
|
|
|
|
|
fi
|
|
|
|
|
# Try to get URL from clipboard
|
|
|
|
|
if [ "${flag_clipboard}" ]; then
|
|
|
|
|
url_to_short=$(xclip -out)
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG : URL to be shortened : ${url_to_short}"
|
|
|
|
|
# ]]]
|
|
|
|
|
|
2020-03-11 16:38:05 +01:00
|
|
|
|
# shorten URL
|
|
|
|
|
result=$(curl -sF"shorten=${url_to_short}" "${null_service_url}")
|
|
|
|
|
|
2020-03-11 16:08:44 +01:00
|
|
|
|
exit 0
|