aboutsummaryrefslogtreecommitdiff
path: root/bin/fnp.sh
blob: ec68e51f77df3529a134fb24dc63112b48c631ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Print input, but include filenames as headings

# Assume stdin if no options given
[ "$#" -gt 0 ] || set -- -

# Iterate through arguments
for arg ; do

    # We'll print the filename "-stdin-" rather than - just to be slightly more
    # explicit
    case $arg in
        -) fn=-stdin- ;;
        *) fn=$arg ;;
    esac

    [ -n "$tail" ] && printf '\n'
    tail=1

    # Form the underline; is there a nicer way to do this in POSIX sh?
    ul=$(printf %s "$fn"|tr '[:print:]' -)
    printf '%s\n%s\n\n' "$fn" "$ul"
    cat -- "$arg"
done