From cddc232e7b5db09f1fe91111d8c6b117902d9b51 Mon Sep 17 00:00:00 2001 From: Yaroslav Surilov Date: Sat, 29 Sep 2018 20:38:09 +0300 Subject: [PATCH] fix using default answer on install (#175) * fix using default answer on install * fix shortening and expanding URLs, simplifying Replace "ki.tc" with more stable and actually working "tinyurl.com" for shortening. Add separate service for expanding any shortened link. Simplifying the code. --- .gitignore | 3 +++ install.sh | 5 +++-- short/short | 13 ++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9e27aac..d121d46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# IDE +.idea + # Meta files .DS_Store Thumbs.db \ No newline at end of file diff --git a/install.sh b/install.sh index 2ba0781..a37377e 100755 --- a/install.sh +++ b/install.sh @@ -9,8 +9,9 @@ prefix="/usr/local" askInstall() { - echo -n "Do you wish to install $1 [Y/n]: " - read -r answer + read -p "Do you wish to install $1 [Y/n]: " answer + answer=${answer:-Y} + if [[ "$answer" == [Yy] ]]; then cd $1 || return 1 echo -n "Installing $1: " diff --git a/short/short b/short/short index 1ba6f6e..77cb610 100755 --- a/short/short +++ b/short/short @@ -136,22 +136,21 @@ expandURL() else url=$1 fi - response=$(httpGet http://ki.tc/short?url=$url) - errorCheck=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['/short']['message']" 2> /dev/null ) - if [[ $errorCheck == "Error in /short" ]]; then + response=$(httpGet https://unshorten.me/s/$url) + errorCheck=$(echo $response) + if [[ $errorCheck == "Invalid Short URL" ]]; then echo "Error: 404 could not find the website" return 1 fi - returnedURL=$(echo $response | python -c "import sys, json; print json.load(sys.stdin)['/short']['destination']" 2> /dev/null ) - + returnedURL=$(echo $response) } shortenURL() { newURL=$1 if [[ $(echo $1 | grep -Eo "^[h]ttp[s]?://") == "" ]]; then newURL="http://"$1; fi -response=$(curl -A curl -s -i -H "Content-Type: application/json" -X POST -d "{\"url\": \"$newURL\"}" http://ki.tc/ || exit 1) -returnedURL=$(echo $response | grep -Eo "http://ki.tc/[0-9a-zA-Z]*" | tail -n 1) +response=$(httpGet http://tinyurl.com/api-create.php?url=$newURL) +returnedURL=$(echo $response) } printResults()