abre
Shorten repetitive text for display. Pipe lines in, get disambiguated lines out.
$ cat paths | abre
/home/user/proj/foo/src/main.rs → /…/foo/src/main.rs
/home/user/proj/bar/src/main.rs → /…/bar/src/main.rs
/home/user/proj/bar/src/lib.rs → /…/bar/src/lib.rs
Install
cargo install abre
Usage
<input> | abre [options]
| Flag | Description | Default |
|---|---|---|
-c <regex> |
Capture group selects the part to shorten | entire line |
-p <preset> |
Use a built-in capture preset | |
-s <chars> |
Separator characters — each char is a separator; common = /_- |
/ |
--suffix |
Shortest unique suffix strategy | |
--truncate [-n N] |
Shorten shared segments to N chars | collapse mode, N=1 |
--ellipsis <str> |
Replacement string for removed parts | … |
--json -k <key> |
JSON line mode, operate on key | |
--add-key <key> |
Write shortened to new key | |
--keep-original <key> |
Modify in place, save original to key |
Presets (-p)
Built-in -c shortcuts for common patterns:
| Preset | Shortens |
|---|---|
url-path |
URL path only, strips scheme and domain |
url-full |
Full URL including domain |
url-domain |
Domain only |
docker |
Image name, keeps tag |
|
# https://github.com/org/repo/issues/1 → /…/issues/1
# https://github.com/org/repo/pulls/2 → /…/pulls/2
Strategies
collapse (default) — trie-based: replaces non-branching middle segments with …, keeps segments needed to disambiguate:
/home/user/proj/foo/src/main.rs → /…/foo/src/main.rs
/home/user/proj/bar/src/main.rs → /…/bar/src/main.rs
/home/user/proj/bar/src/lib.rs → /…/bar/src/lib.rs
suffix — shortest unique trailing segment(s) per line:
/home/user/proj/foo/src/main.rs → /…/foo/src/main.rs
/home/user/proj/bar/src/main.rs → /…/bar/src/main.rs
/home/user/proj/bar/src/lib.rs → /…/lib.rs
truncate — shorten shared prefix segments to N chars (default 1):
/home/user/proj/foo/src/main.rs → /h/u/p/foo/src/main.rs
/home/user/proj/bar/src/main.rs → /h/u/p/bar/src/main.rs
Multiple separators
Pass multiple characters to -s — each is treated as a separator. The original separator between each segment is preserved in the output.
# Split on both / and -
|
# "common" preset covers /_-
|
# Java packages with dot separator
|
Examples
# file paths
|
# URL paths (strips scheme + domain)
|
# Docker images — shorten image names, keep tags
|
# Java/Kotlin package names
|
# Mixed separators (path + hyphen + underscore)
|
JSON mode
Operate on a key in JSON lines (one object per line).
Input
Modify in place (default)
|
URLs 1 & 2 keep frontend because they share the repo — issues vs pulls is the branching point. URLs 3 & 4 diverge higher up so more gets collapsed.
Add new key (--add-key)
|
Original stays intact, shortened value goes into short.
Modify in place, keep original (--keep-original)
|
Shortened goes into url, original backed up to full_url.
Planned
--width N— smart collapse to fit within N chars. Unlike dumb truncation (cut -c), uses segment structure to collapse more aggressively from the left until it fits the budget. e.g.--width 30on/org/frontend/issues/42→/org/…/issues/42