]> git.rmz.io Git - dotfiles.git/commitdiff
bin: add script to shorten text to N chars or Term width
authorSamir Benmendil <me@rmz.io>
Thu, 13 Apr 2023 01:01:34 +0000 (02:01 +0100)
committerSamir Benmendil <me@rmz.io>
Sun, 17 Dec 2023 17:36:17 +0000 (17:36 +0000)
bin/shorten [new file with mode: 0755]

diff --git a/bin/shorten b/bin/shorten
new file mode 100755 (executable)
index 0000000..33f41f2
--- /dev/null
@@ -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…/"