-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathalmanac
executable file
·115 lines (96 loc) · 3.64 KB
/
almanac
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
while getopts "d:" OPTION; do
case $OPTION in
d)
DIFFTOOL=${OPTARG}
;;
*)
echo "Unknow comandline switch: $OPTION"
exit 1
esac
done
if ! command -v yq &> /dev/null; then
echo "Could not find 'yq'."
echo "Please visit https://github.com/mikefarah/yq/#install"
exit 1
fi
CH_CFG_PATH=~/.chia/mainnet/config/config.yaml
if [[ ! -f $CH_CFG_PATH ]]; then
echo "Could not find $CH_CFG_PATH"
exit 1
fi
if [[ "$(git rev-parse --show-toplevel 2>/dev/null)" != $(pwd -P) ]]; then
echo "Not in chia-blockchain project root."
exit 1
fi
python -m pip freeze | grep 'pyaml' > /dev/null 2>&1
RESULT=$?
if [[ $RESULT -eq 1 ]]; then
echo "This requires the python module 'pyaml'."
echo "Install this with 'pip install pyaml' and try again."
exit 1
fi
GIT_REMOTE=$(git remote -v 2>/dev/null | head -n1 | awk '{print $2}')
REPO=$(echo "${GIT_REMOTE}" | sed -e 's,.*:\(.*/\)\?,,' -e 's/\.git$//')
if [[ $REPO != chia-blockchain ]]; then
echo "You must run this command from the chia-blockchain project root."
exit 1
fi
TMPCUR=$(mktemp /tmp/curconfXXXXXXXXXX)
TMPNEW=$(mktemp /tmp/newconfXXXXXXXXXX)
TMPNOPOOL=$(mktemp /tmp/nopoolXXXXXXXXXX)
CH_CFG_INIT=$PWD/chia/util/initial-config.yaml
CUR_TS=$(date "+%d%b%Y_%H-%M-%S")
CH_CFG_BAK=$CH_CFG_PATH-$CUR_TS
TOOL=${DIFFTOOL:-vimdiff}
yq --front-matter=process '.pool.pool_list=[]' "$CH_CFG_PATH" > "$TMPNOPOOL"
yq '.pool.pool_list' "$CH_CFG_PATH" -s '"/tmp/tmppool"'
python -m pyaml "$TMPNOPOOL" > "$TMPCUR"
python -m pyaml "$CH_CFG_INIT" > "$TMPNEW"
export BOLD=$(tput bold)
export RESET=$(tput sgr0)
export BLUE=$(tput setaf 4)
export PURP=$(tput setaf 186)
export YEL=$(tput setaf 203)
export WHT=$(tput setaf 231)
VIMDIFF_CONTROLS=$(bat -Ppl cmd-help <<- EOF
${PURP}VIMDIFF CONTROLS ~${RESET}
${YEL}|${RESET} ${WHT} ]c | advance to the next block with differences ${RESET}
${YEL}|${RESET} ${WHT} [c | reverse search for the previous block with differences ${RESET}
${YEL}|${RESET} ${WHT} do | bring changes from the other file to the current file ${RESET}
${YEL}|${RESET} ${WHT} dp | send changes from the current file to the other file ${RESET}
${YEL}|${RESET} ${WHT} zo | unfold/unhide text ${RESET}
${YEL}|${RESET} ${WHT} zc | refold/rehide text ${RESET}
${YEL}|${RESET} ${WHT} zr | unfold both files completely ${RESET}
${YEL}|${RESET} ${WHT} zm | fold both files completely ${RESET}
${YEL}NOTE ABOUT DIFF OBTAIN/PUT CONTROL${RESET}${WHT}:${RESET}
${WHT}- ${BOLD}${YEL}Normal Mode${RESET}${WHT}: ${PURP}Use "do" and "dp" controls when your cursor is on, or just one line under a block.${RESET}
${WHT}- ${BOLD}${YEL}Visual Mode${RESET}${WHT}: ${PURP}Use ":'<,'>diffget" and ":'<,'>diffput" when selecting lines of text.${RESET}
${PURP} See also ":h copy-diffs".${RESET}
${PURP}":diffupdate"${RESET}${WHT} will re-scan the files for changes.${RESET}
${PURP}When you are finished editing, press "escape", and enter ":wqa" and press "enter".${RESET}
EOF
)
echo "You will now see a diff view of:"
echo "$CH_CFG_PATH"
echo "and"
echo "$CH_CFG_INIT"
echo "This will open in $TOOL."
if [[ $TOOL == "vimdiff" ]]; then
echo -e "$VIMDIFF_CONTROLS"
echo ""
fi
read -rp "Press enter to continue."
$TOOL "$TMPCUR" "$TMPNEW"
read -r -p "Do you want to replace your current Chia config file with your saved changes? [y/N] " CFG_CONFIRM
case "$CFG_CONFIRM" in
[yY][eE][sS]|[yY])
mv "$CH_CFG_PATH" "$CH_CFG_BAK"
#cp "$TMPCUR" "$CH_CFG_PATH"
yq '.pool.pool_list |=load("/tmp/tmppool.yml")' "$TMPCUR" > "$CH_CFG_PATH"
;;
*)
exit 0
;;
esac
rm "$TMPCUR" "$TMPNEW" /tmp/tmppool.yml