:)
This commit is contained in:
parent
8d167995c7
commit
43c9688558
6 changed files with 38 additions and 21 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
: "${1:?Missing filename!}"
|
||||
[ ! -f "$1" ] && { echo "Wrong filename!" >&2; exit 1; }
|
||||
|
||||
FILENAME="$(mktemp)"
|
||||
|
||||
|
|
@ -11,16 +12,18 @@ cleanup() {
|
|||
trap 'cleanup' INT HUP TRAP
|
||||
|
||||
shift_header() {
|
||||
read -r line < "$1"
|
||||
|
||||
if [[ "$line" = "# "* ]]; then
|
||||
echo "---"
|
||||
echo "title: ${line#"# "}"
|
||||
echo "---"
|
||||
tail -n +2 "$1"
|
||||
else
|
||||
cat "$1"
|
||||
fi
|
||||
local counter=1
|
||||
while read -r line; do
|
||||
(( counter+=1 ))
|
||||
if [[ "$line" = "# "* ]]; then
|
||||
echo "---"
|
||||
echo "title: ${line#"# "}"
|
||||
echo "---"
|
||||
tail -n +"$counter" < "$1"
|
||||
return
|
||||
fi
|
||||
done < "$1"
|
||||
cat "$1"
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue