dotfiles/shell/profile.d/print-front-matter.sh
2025-09-09 00:23:03 -06:00

18 lines
367 B
Bash

#!/bin/sh
f_print_front_matter() {
file="$1"
if [ -z "$file" ] || ! [ -f "$file" ]; then
echo "File '$file' not found"
return 1
fi
if command -v batcat >/dev/null 2>&1; then
PAGER="batcat -p -l sh"
else
PAGER=less
fi
awk '$0 ~ /#!/ {next} $0 !~ /#/ {exit} {line = $0; sub(/^#[[:space:]]*/, "", line); print line}' "$file" | $PAGER
}