Skip to content

Instantly share code, notes, and snippets.

@MicroDroid
Last active October 18, 2021 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MicroDroid/4055cdee222ac973c0b6c888448840d6 to your computer and use it in GitHub Desktop.
Save MicroDroid/4055cdee222ac973c0b6c888448840d6 to your computer and use it in GitHub Desktop.
Script to replace URL in clipboard with a shorter one using zws.im, probably assign a keyboard shortcut to run this script.
original=`xclip -o -sel clipboard`
if [[ $original == https://zws.im* ]]; then
notify-send "Already shortened" --icon=gtk-edit
exit 1;
fi
json=$(curl -s "https://us-central1-zero-width-shortener.cloudfunctions.net/shortenURL?url=$original")
if [ $? -eq 0 ]; then
short="https://zws.im/$(echo $json | jq -jr '.short')"
if [ $? -eq 0 ]; then
printf $short | xclip -sel clip
notify-send "Link shortened" --icon=stock_cut
else
notify-send "Shortening failed" --icon=gtk-quit
fi
else
notify-send "Shortening failed" --icon=gtk-quit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment