-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown-headers-decrease-after-subnote-extract.sh
More file actions
executable file
·53 lines (38 loc) · 1.29 KB
/
Copy pathmarkdown-headers-decrease-after-subnote-extract.sh
File metadata and controls
executable file
·53 lines (38 loc) · 1.29 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
function echoerr {
printf "%s\n" "$*" >&2;
}
FILE_NAME="$1"
if [[ -z "$FILE_NAME" ]]; then
echoerr "Error: file name was not provided! Exitting..."
exit 1
fi
function ask_continue { action_name=$1
if [[ -z "${action_name}" ]]; then
action_name="continue"
fi
# -s do not echo input coming from a terminal
# -p prompt output the string PROMPT without a trailing newline before
# attempting to read
# -r do not allow backslashes to escape any characters
# -n nchars return after reading NCHARS characters rather than waiting
# for a newline,
read -n 1 -r -p "Press \"y\" to ${action_name}: " input
# new line but with stderr, escaping capture output
echo >&2
if [ "$input" != "Y" ] && [ "$input" != "y" ] && [ "$input" != "д" ] && [ "$input" != "Д" ]; then
exit
fi
echo 1
}
printf "\n# Current headers state\n\n"
( set -x; rg "^#" "$FILE_NAME" )
printf "\n# After planned changes\n\n"
( set -x; rg "^#" --replace "" "$FILE_NAME" )
printf "\n"
if [[ "$(ask_continue 'apply replacement')" != "1" ]]; then
echoerr "You choosed to cancel the replacement. Exitting"
exit;
fi
( set -x; wrg "^#" --replace "" "$FILE_NAME" )
# TODO git commit with default message: "$FILE_NAME": fix headers level after subnote extraction