A command-line interface for Shlink, the self-hosted URL shortener. Written in Bash with no dependencies beyond curl and jq.
Shlink ships with its own CLI, but that tool runs on the server itself and requires direct access to the Shlink installation. This project talks to Shlink's REST API instead, so you can manage your short URLs from any machine without SSH access or server-side tooling.
-
Download the
shlinkscript and make it executable:chmod +x shlink
-
Place it somewhere in your
$PATH(e.g./usr/local/bin/or~/.local/bin/). -
Set the required environment variables:
export SHLINK_API="https://s.example.com" export SHLINK_API_KEY="your-api-key"
Optionally set the API version (defaults to 3):
export SHLINK_API_VERSION=3
Bash -- add to ~/.bashrc:
source /path/to/shlink-completion.bashZSH -- copy _shlink into your $fpath:
mkdir -p ~/.zsh/completions
cp _shlink ~/.zsh/completions/
# Add to ~/.zshrc:
fpath=(~/.zsh/completions $fpath)
autoload -Uz compinit && compinitBoth completions provide dynamic tag completion by querying your Shlink instance.
shlink --help
shlink 1.0.0 - CLI for Shlink URL shortener
Usage: shlink [-q|--quiet] [-j|--json] COMMAND [ARGS...]
Short URLs:
list List short URLs
create URL Create a new short URL
get CODE Get short URL details
edit CODE Edit a short URL
delete CODE Delete a short URL
Tags:
tags List all tags
tag-stats List tags with statistics
tag-rename OLD NEW Rename a tag
tag-delete TAG... Delete tags
Visits:
visits General visit statistics
visits-url CODE Visits for a short URL
visits-tag TAG Visits for a tag
visits-domain DOMAIN Visits for a domain
visits-orphan Orphan visits
visits-delete-url Delete visits for a short URL
visits-delete-orphan Delete all orphan visits
Domains:
domains List configured domains
Redirect Rules:
redirect-rules CODE List redirect rules
redirect-rules-set CODE JSON Set redirect rules
Other:
api METHOD PATH [BODY] Raw API call
help [COMMAND] Show help
version Show version
Global Options:
-q, --quiet Minimal output (for scripting)
-j, --json Output raw JSON
-h, --help Show help
Environment Variables:
SHLINK_API Base URL of the Shlink instance
SHLINK_API_KEY API key for authentication
SHLINK_API_VERSION API version (default: 3)
Run 'shlink help COMMAND' for details on a specific command.