STRING-SHORTEN(1)

πŸŽ€ STRING-SHORTEN(1) πŸŽ€

okay bestie, welcome to string-shorten β€” the fish-shell command that trims your strings down to a width and slaps an ellipsis on the end. it's giving "cropped but make it informative" ✨

✨ SYNOPSIS ✨

string shorten [(-c | --char) CHARS] [(-m | --max) INTEGER]
               [-N | --no-newline] [-l | --left] [-q | --quiet] [STRING ...]

πŸ’– DESCRIPTION πŸ’–

string shorten truncates every STRING down to the given visible width and then adds an ellipsis so everyone knows something got cut. and what's "visible width" bestie? it's the width of all the visible characters added together β€” escape sequences don't count, and it accounts for fish_emoji_width <#envvar-fish_emoji_width> and fish_ambiguous_width <#envvar-fish_ambiguous_width>. basically: how many terminal columns the STRING actually eats up. πŸ“

the escape sequences it knows about are the ones fish itself knows about and how fish computes its output. no cap, your terminal might support more escapes than that β€” or it might not support some of the escapes fish knows about. πŸ™ˆ

  • -m, --max β€” if you pass it, truncate at that given width. if you don't, the lowest non-zero width out of all the input strings gets used. and a max of 0 means no shortening happens at all β€” every STRING prints as-is. πŸ’…
  • -N, --no-newline β€” only the first line of each STRING gets used (or the last line if you also pass --left), and an ellipsis gets added if it was multiline. heads up though: this only works for STRINGs you pass as arguments β€” multiple lines coming in on stdin get interpreted as separate STRINGs instead. πŸ‘‘
  • -c, --char β€” add CHAR instead of an ellipsis. it can also be empty, or more than one character. your call, main character. πŸ¦‹
  • -l, --left β€” remove text from the left instead, so it prints the longest suffix of the string that fits. pair it with --no-newline and it'll take from the last line instead of the first. 🌸
  • -q, --quiet β€” string shorten only runs for the return value: if anything would be shortened it returns 0, otherwise 1. silent but observant, iykyk. 🀫

the default ellipsis is …. if fish thinks your system can't handle it because of your locale, it'll use ... instead. flexible queen. πŸ’œ

the return value is 0 if any shortening happened, 1 otherwise. periodt.


🌈 EXAMPLES 🌈

>_ string shorten foo foobar
# No width was given, we infer, and "foo" is the shortest.
foo
fo…
>_ string shorten --char="..." foo foobar
# The target width is 3 because of "foo",
# and our ellipsis is 3 too, so we can't really show anything.
# This is the default ellipsis if your locale doesn't allow "…".
foo
...
>_ string shorten --char="" --max 4 abcdef 123456
# Leaving the char empty makes us not add an ellipsis
# So this truncates at 4 columns:
abcd
1234
>_ touch "a multiline"\n"file"
>_ for file in *; string shorten -N -- $file; end
# Shorten the multiline file so we only show one line per file:
a multiline…
>_ ss -p | string shorten -m$COLUMNS -c ""
# `ss` from Linux' iproute2 shows socket information, but prints extremely long lines.
# This shortens input so it fits on the screen without overflowing lines.
>_ git branch | string match -rg '^\* (.*)' | string shorten -m20
# Take the current git branch and shorten it at 20 columns.
# Here the branch is "builtin-path-with-expand"
builtin-path-with-e…
>_ git branch | string match -rg '^\* (.*)' | string shorten -m20 --left
# Taking 20 columns from the right instead:
…in-path-with-expand

🫢 SEE ALSO 🫢

  • string pad does the literal inverse of this command β€” it adds padding out to a specific width instead. ✨
  • the printf command can do simple padding too β€” for example printf %10s\n works just like string pad -w10. πŸ”₯
  • string length with the --visible option is your girl for showing what fish thinks the width is. πŸ’…

fish-shell developers


k bye bestie, go shorten something πŸ’– this was fish-shell version 4.9, dated Sep 08, 2026 β€” copyright belongs to the fish-shell developers, mwah πŸŽ€πŸ¦‹πŸ’œ
πŸ“¦ where this page comes from
  • arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms