-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite-one-line
executable file
·41 lines (33 loc) · 1.09 KB
/
write-one-line
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
set -euo pipefail
book="pan-tadeusz-adam-mickiewicz.md"
source ./_pointer
if [ "$pointer" -eq 0 ]; then
exit 1
fi
line=$(sed -n "${pointer}p" src.md)
commit_message=$(echo -n "$line" | tr -d "\n" | tr -d "\r")
line=$(echo -n "$commit_message" | sed -E "s/^ /\ \ \ \ /")
if [[ ${line:0:1} == "#" ]] || [[ ${line:0:1} == ">" ]]; then
# if it's a heading, or blokquote, do not append "enter"
echo -e "$line\n$(cat "$book")" > "$book"
elif [[ $line == "" ]]; then
# if the line is empty, do not append the "enter"
echo -e "\n$(cat "$book")" > "$book"
else
next=$((pointer + 1))
next_line=$(sed -n "${next}p" src.md)
next_line=$(echo -n "$next_line" | tr -d "\n" | tr -d "\r")
if [[ $next_line == "" ]]; then
# if the next line was empty, do not append "enter"
echo -e "$line\n$(cat "$book")" > "$book"
else
echo -e "$line\\\\\n$(cat "$book")" > "$book"
fi
fi
[ "$commit_message" == "" ] && commit_message="_"
pointer=$((pointer - 1))
echo "pointer=$pointer" > _pointer
git add "$book"
git commit -m "$commit_message"
#git push origin main