aboutsummaryrefslogtreecommitdiffstats
path: root/cat-with-head
diff options
context:
space:
mode:
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