From: Samir Benmendil Date: Thu, 13 Apr 2023 01:01:34 +0000 (+0100) Subject: bin: add script to shorten text to N chars or Term width X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/4cd8f8e36349770472140db8e46a1a0a675032c8?ds=sidebyside bin: add script to shorten text to N chars or Term width --- diff --git a/bin/shorten b/bin/shorten new file mode 100755 index 0000000..33f41f2 --- /dev/null +++ b/bin/shorten @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# https://brettterpstra.com/2016/04/27/shell-tricks-shorten-every-line-of-output/ + +#TODO allow different width to be set +c=$(tput cols) +w=$((c - 1)) +cat | sed -E "s/(.{$w}).*$/\1…/"