├── LICENSE ├── yourls └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 ྅༻ Ǭɀħ ༄༆ཉ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /yourls: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Configure these 2 lines and leave the rest 4 | YOURLS_HOST="https://sho.rt/" 5 | YOURLS_KEY="eb9444558f" # see sho.rt/admin/tools.php 6 | 7 | yourls_help() { 8 | echo "Shorten URLs with YOURLS" 9 | echo 10 | echo "Usage:" 11 | echo " ${0##*/} " 12 | echo " ${0##*/} -k -t -f <FORMAT>" 13 | echo " ${0##*/} <url> --help" 14 | echo 15 | echo "Options:" 16 | echo " -h | --help Show this screen" 17 | echo " -k | --keyword <KEYWORD> Custom keyword" 18 | echo " -t | --title <TITLE> Custom title" 19 | echo " -f | --format <FORMAT> Ouput format (json, xml, simple)" 20 | exit 1 21 | } 22 | 23 | # If no param or param is -h|--help 24 | if [ -z "$1" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then 25 | yourls_help 26 | fi 27 | 28 | # Assuming first parameter is the URL 29 | URL=$1; 30 | shift; 31 | 32 | POSITIONAL=() 33 | while [[ $# -gt 0 ]] 34 | do 35 | key="$1" 36 | case $key in 37 | -k|--keyword) 38 | KEYWORD="$2" 39 | shift # argument 40 | shift # value 41 | ;; 42 | -t|--title) 43 | TITLE="$2" 44 | shift # argument 45 | shift # value 46 | ;; 47 | -f|--format) 48 | FORMAT="$2" 49 | shift # argument 50 | shift # value 51 | ;; 52 | -h|--help) 53 | yourls_help 54 | exit 1 55 | ;; 56 | *) # unknown option 57 | echo "${0##*/}: unknown option $1" 58 | echo "Try '${0##*/} --help' for more information." 59 | exit 1 60 | ;; 61 | esac 62 | done 63 | 64 | if [ -z "$FORMAT" ]; then 65 | FORMAT="simple" 66 | fi 67 | 68 | curl -s "$YOURLS_HOST/yourls-api.php?signature=$YOURLS_KEY&action=shorturl&url=$URL&keyword=$KEYWORD&title=$TITLE&format=$FORMAT" 69 | 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YOURLS BASH [![Listed in Awesome YOURLS!](https://img.shields.io/badge/Awesome-YOURLS-C5A3BE)](https://github.com/YOURLS/awesome-yourls/) 2 | A simple bash script to shorten URLs with [YOURLS](https://yourls.org) 3 | 4 | ![image](https://user-images.githubusercontent.com/223647/120930653-8a50cf80-c6ee-11eb-8972-22197382bfa4.png) 5 | 6 | ## Installation 7 | 8 | ```shell 9 | # using wget 10 | $> wget -q https://raw.githubusercontent.com/ozh/yourls-bash/master/yourls 11 | # using curl 12 | $> curl -s -o yourls https://raw.githubusercontent.com/ozh/yourls-bash/master/yourls 13 | ``` 14 | 15 | Then, edit the two parameters at the beginning of the script (`YOURLS_HOST` and `YOURLS_KEY`) to match your setup. 16 | 17 | Depending on your setup, you may want to make this file executable (`chmod +x yourls`) and in your $PATH (eg `~/bin` maybe) 18 | 19 | ## Usage 20 | 21 | Shorten a long URL : 22 | 23 | ```bash 24 | $> yourls https://someverylongdomain.com 25 | https://sho.rt/ef 26 | ``` 27 | 28 | Shorten a long URL and provide a custom keyword and a custom title : 29 | 30 | ```bash 31 | $> yourls https://someverylongurl.com -k test12 --title "Some title" 32 | https://sho.rt/test12 33 | ``` 34 | 35 | Shorten a URL and receive JSON output, for instance to display with `jq` : 36 | ```bash 37 | $> yourls https://example.com -f json | jq 38 | { 39 | "url": { 40 | "keyword": "Nzs", 41 | "url": "https://example.com", 42 | "title": "Example Domain", 43 | "date": "2021-06-06 16:03:44", 44 | "ip": "127.0.0.1" 45 | }, 46 | "status": "success", 47 | "message": "http://example.com added to database", 48 | "title": "Example Domain", 49 | "shorturl": "http://sho.rt/Nzs", 50 | "statusCode": 200 51 | } 52 | ``` 53 | 54 | Display help message : 55 | ```bash 56 | $> yourls --help 57 | ``` 58 | 59 | ## License 60 | 61 | Do whatever the hell you want with it 62 | 63 | 64 | 65 | --------------------------------------------------------------------------------