From ccc57af1ed199a2b41bdcaf0e2363afe126bc109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BE=85=E0=BC=BB=20=C7=AC=C9=80=C4=A7=20=E0=BC=84?= =?UTF-8?q?=E0=BC=86=E0=BD=89?= Date: Sun, 6 Jun 2021 17:30:10 +0200 Subject: [PATCH] Create yourls --- yourls | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 yourls diff --git a/yourls b/yourls new file mode 100644 index 0000000..69aa45e --- /dev/null +++ b/yourls @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +# Configure these 2 lines and leave the rest +YOURLS_HOST="https://sho.rt/" +YOURLS_KEY="eb9444558f" # see sho.rt/admin/tools.php + +yourls_help() { + echo "Shorten URLs with YOURLS" + echo + echo "Usage:" + echo " ${0##*/} " + echo " ${0##*/} -k -t -f <FORMAT>" + echo " ${0##*/} <url> --help" + echo + echo "Options:" + echo " -h | --help Show this screen" + echo " -k | --keyword <KEYWORD> Custom keyword" + echo " -t | --title <TITLE> Custom title" + echo " -f | --format <FORMAT> Ouput format (json, xml, simple)" + exit 1 +} + +# If no param or param is -h|--help +if [ -z "$1" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then + yourls_help +fi + +# Assuming first parameter is the URL +URL=$1; +shift; + +POSITIONAL=() +while [[ $# -gt 0 ]] +do + key="$1" + case $key in + -k|--keyword) + KEYWORD="$2" + shift # argument + shift # value + ;; + -t|--title) + TITLE="$2" + shift # argument + shift # value + ;; + -f|--format) + FORMAT="$2" + shift # argument + shift # value + ;; + -h|--help) + yourls_help + exit 1 + ;; + *) # unknown option + echo "${0##*/}: unknown option $1" + echo "Try '${0##*/} --help' for more information." + exit 1 + ;; + esac +done + +if [ -z "$FORMAT" ]; then + FORMAT="simple" +fi + +curl -s "$YOURLS_HOST/yourls-api.php?signature=$YOURLS_KEY&action=shorturl&url=$URL&keyword=$KEYWORD&title=$TITLE&format=$FORMAT" +