Skip to main content

A simple CLI URL shortener for multiple url-shortening services, with optional clipboard copy.

Project description

lain-shorten

A simple CLI URL shortener for multiple url-shortening services, with optional clipboard copy.

Installation

Via PyPI (Recommended)

You have the option to choose between the standard version (lain-shorten) or the desktop version (lain-shorten[clipboard]), which adds clipboard support for auto-copying links.

[!NOTE] For brevity, the examples below use the desktop version.

With pip (Basic)

pip install "lain-shorten[clipboard]"

With pipx (Isolated)

pipx install "lain-shorten[clipboard]"

With uv (Best)

The most efficient way to install or run the shortener.

# Permanent isolated installation
uv tool install "lain-shorten[clipboard]"

# Run once without installing
uvx --with "lain-shorten[clipboard]" lain-shorten <url1> <url2> <url3>

# Run in scripts or ad-hoc environments
uv run --with "lain-shorten[clipboard]" lain-shorten <url1> <url2> <url3>

From Source (Development)

# Clone the repository and navigate to it
git clone git@github.com:NecRaul/lain-shorten.git
cd lain-shorten

# Install environment and all development dependencies (mandatory and optional)
uv sync --dev

# Install pre-commit hook
uv run pre-commit install

# Optional: Run all linters and type checkers manually
uv run pre-commit run --all-files

# Run the local version
uv run lain-shorten <url1> <url2> <url3>

# Run tests
uv run pytest tests

Usage

Simply provide a URL, and the tool will automatically handle protocol validation and formatting.

Use --open to open each generated short URL in your default browser right after shortening. This makes it easy to verify each format resolves as expected in a real browser session.

# Shorten a URL (default shortener: lainla)
lain-shorten https://kuroneko.dev

# Protocol-less (automatically prepends http://)
lain-shorten kuroneko.dev

# Select a specific shortener
lain-shorten --host wildlain https://github.com/NecRaul

# Shorten using every available host
lain-shorten --host all https://gist.github.com/NecRaul

# irc
lain-shorten irc://irc.libera.chat/#archlinux

# ssh
lain-shorten ssh://necraul@kuroneko.dev

# mailto
lain-shorten mailto:necraul@kuroneko.dev

# sms
lain-shorten sms:+15551234567

# magnet torrent
lain-shorten "magnet:?xt=urn:btih:0123456789abcdef0123456789abcdef01234567&dn=Example"

# Open shortened URLs using the default browser
lain-shorten --open \
    http://kuroneko.dev \
    ircs://irc.libera.chat:6697/#archlinux \
    xmpp:necraul@kuroneko.dev \
    tel:+15551234567

# Display help and version
lain-shorten -h
lain-shorten -v

Supported Shorteners

Supported Schemes

  • http:// and https:// links.
  • protocol-less domains (automatically normalized to http://).
  • irc:// and ircs:// links.
  • ssh:// links.
  • mailto:// and xmpp:// links.
  • sms:// and tel:// links.
  • magnet: torrent links.

Configuration

lain-shorten supports a JSON configuration file to set a default shortener and whether to open shortened URLs in your browser. You can create a default config, inspect the effective configuration, and override or ignore the config file at runtime.

  • Default path
    • Linux/BSD: $XDG_CONFIG_HOME/necraul/lain-shorten.json or ~/.config/necraul/lain-shorten.json
    • MacOS: ~/Library/Application Support/necraul/lain-shorten.json
    • Windows: %APPDATA%/necraul/lain-shorten.json
  • Basic structure
    • default_shortener: shortener used when --shortener flag is omitted (default: "lainla").
    • open_urls: whether to open each generated short URL in your default browser (default: false).
{
  "default_shortener": "lainla",
  "open_urls": false
}
# Create a default configuration file at the default path
lain-shorten --init-config

# Create a default configuration file at a custom path
lain-shorten --init-config config.json

# Show the effective configuration (defaults merged with the default config file)
lain-shorten --show-config

# Create a default configuration file at the default path and print it
lain-shorten --init-config --show-config

# Create a default configuration file at a custom path and print it
lain-shorten --init-config /path/to/config.json --show-config

# Show the effective configuration (defaults merged with the custom config file)
lain-shorten --config config.json --show-config

# Shorten URLs using the config file's default_shortener (no --shortener needed)
lain-shorten https://kuroneko.dev/

# Override the config file's default_shortener
lain-shorten --shortener wildlain https://github.com/NecRaul

# Use a custom configuration file
lain-shorten --config /path/to/config.json https://gist.github.com/NecRaul

# Ignore the configuration file and use only CLI flags
lain-shorten --no-config https://kuroneko.dev/

# Open shortened URLs in your browser (CLI flag overrides config)
lain-shorten --open https://github.com/NecRaul/

Dependencies

  • requests: send the API request for shortening.

Optional

  • pyperclip: copy the shortened URLs to the clipboard.

How it works

Supported services allow shortening URLs via an HTTP request.

This tool automates the process to avoid typing long curl strings.

The Manual Way

curl -d "url=https://kuroneko.dev" https://s.lain.la

The lain-shorten way

  • Batch Processing: Shorten multiple URLs in a single command execution, saving time over individual manual requests.
  • Validation: Uses urllib to ensure the URL is formatted correctly.
  • API Request: Sends the POST request via requests.
  • Normalization: Automatically adds http:// if missing.
  • Clipboard (Optional): If pyperclip is installed, the result is instantly copied to your clipboard.

Special thanks

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lain_shorten-1.20.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lain_shorten-1.20-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file lain_shorten-1.20.tar.gz.

File metadata

  • Download URL: lain_shorten-1.20.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lain_shorten-1.20.tar.gz
Algorithm Hash digest
SHA256 2aa33ac4891b89fce9380d305830cf61dc31039ea621457a67b4351e60410e1b
MD5 ce6b473332e8dae3d492656381a6b393
BLAKE2b-256 ddc5b8a9578e3b72c623c1f3c57912ae6b100ff061d1411c951d205e8004b164

See more details on using hashes here.

File details

Details for the file lain_shorten-1.20-py3-none-any.whl.

File metadata

  • Download URL: lain_shorten-1.20-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lain_shorten-1.20-py3-none-any.whl
Algorithm Hash digest
SHA256 3c54879c1199149dadb4cee7d489abc22ae2157d90904d2017f444bd0f10bc48
MD5 bb3b3167c13ed4696df751d7779b6afa
BLAKE2b-256 a0ffe0e1fde3f418914b09424977ba14c7a18fcb75ea97da7b9434d7dd3d6784

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page