A simple Bash script to shorten URLs using the YOURLS API. This script allows you to easily generate short links directly from your command line.
Inspirated from https://github.com/ozh/yourls-bash
- Shortens URLs using a configurable YOURLS instance.
- Supports custom keywords and titles.
- Outputs results in multiple formats (JSON, XML, Simple).
- Configuration is stored in an external file for easy access.
curl
command-line tool installed on your system.- Access to a YOURLS instance with an API key.
- Clone this repository or download the script.
- Make the script executable:
chmod +x yourls
Before using the script, you need to set up the YOURLS configuration.
The script checks for the configuration file at ~/.config/shortlink.conf
. If it doesn't exist, the script will prompt you to create one.
To create the configuration file:
-
Run the script:
./yourls
-
When prompted, enter the YOURLS host URL (e.g.,
https://sho.rt/
) and your YOURLS API key.
YOURLS_HOST="https://sho.rt/"
YOURLS_KEY="eb9444558f"
You can use the script to shorten URLs in the following ways:
./yourls <URL>
-k
,--keyword <KEYWORD>
: Specify a custom keyword for the shortened URL.-t
,--title <TITLE>
: Specify a custom title for the URL.-f
,--format <FORMAT>
: Specify the output format (json, xml, simple; default: simple).-h
,--help
: Show the help message.
./yourls https://example.com
./yourls https://example.com -k mykeyword -t "My Example"
./yourls https://example.com -f json
The script will display both the original URL and the shortened URL. In case of any errors, appropriate messages will be shown.
Original URL: https://example.com
Shortened URL: https://sho.rt/abc123
Feel free to submit pull requests or issues to improve this script!