Skip to content

masdzub/bash-yourls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

YOURLS URL Shortener Script

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

Command Usage

Features

  • 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.

Requirements

  • curl command-line tool installed on your system.
  • Access to a YOURLS instance with an API key.

Installation

  1. Clone this repository or download the script.
  2. Make the script executable:
    chmod +x yourls

Configuration

Before using the script, you need to set up the YOURLS configuration.

Create Configuration File

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:

  1. Run the script:

    ./yourls
  2. When prompted, enter the YOURLS host URL (e.g., https://sho.rt/) and your YOURLS API key.

Example Configuration File (~/.config/shortlink.conf)

YOURLS_HOST="https://sho.rt/"
YOURLS_KEY="eb9444558f"

Usage

You can use the script to shorten URLs in the following ways:

Shorten a URL

./yourls <URL>

Options

  • -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.

Examples

Shorten a URL without options

./yourls https://example.com

Shorten a URL with a custom keyword and title

./yourls https://example.com -k mykeyword -t "My Example"

Shorten a URL with JSON output format

./yourls https://example.com -f json

Output

The script will display both the original URL and the shortened URL. In case of any errors, appropriate messages will be shown.

Sample Output

Original URL: https://example.com
Shortened URL: https://sho.rt/abc123

Contributing

Feel free to submit pull requests or issues to improve this script!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages