aboutsummaryrefslogtreecommitdiffstats
path: root/cat-with-head
blob: 81e73bd2d7fc7bd021b78029ed4ddbede69c6a5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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