aboutsummaryrefslogtreecommitdiffstats
path: root/cat-with-head
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-02-18 13:22:42 +0100
committerMattias Andrée <maandree@kth.se>2024-02-18 13:22:42 +0100
commitc274475635d410c0e9f812e71d20183cb923cd6b (patch)
tree70f59c3b28a36921ea46a93effc565d59e20f43b /cat-with-head
parentAdd makeenv (diff)
downloaddotfiles-c274475635d410c0e9f812e71d20183cb923cd6b.tar.gz
dotfiles-c274475635d410c0e9f812e71d20183cb923cd6b.tar.bz2
dotfiles-c274475635d410c0e9f812e71d20183cb923cd6b.tar.xz
misc updates
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'cat-with-head')
-rwxr-xr-xcat-with-head19
1 files changed, 19 insertions, 0 deletions
diff --git a/cat-with-head b/cat-with-head
new file mode 100755
index 0000000..81e73bd
--- /dev/null
+++ b/cat-with-head
@@ -0,0 +1,19 @@
+#!/bin/sh
+set -e
+home="$(printf '%s\n' "$HOME" | sed 's:/\+:/:g' | sed '$s:/$::g')"
+if test -z "$(printf '%s\n' "$home" | tr -d '[A-Za-z0-9_/-]')"; then
+ pretty_filename () {
+ printf '%s' "$1" | sed '1s:^'"${home}"'/:~/:' | sed 's:/\+:/:g'
+ }
+else
+ pretty_filename () {
+ printf '%s' "$1" | sed 's:/\+:/:g'
+ }
+fi
+if test "$1" = "--"; then
+ shift 1
+fi
+for file; do
+ printf '\n\n\n### %s\n\n' "$(pretty_filename "$(realpath -- "$file")")"
+ cat -- "$file"
+done