最后活跃于 1 month ago

gistfile1.txt 原始文件
1function peers::cleanup_config() {
2 local config
3 config=$(config::config_file)
4
5 python3 -c "
6import re
7config = open('${config}').read()
8
9# Normalize multiple blank lines to single blank line
10config = re.sub(r'\n{3,}', '\n\n', config)
11
12# Ensure file ends with single newline
13config = config.rstrip('\n') + '\n'
14
15open('${config}', 'w').write(config)
16"
17}
18
19function peers::remove_block() {
20 local name="$1"
21 local config
22 config=$(config::config_file)
23
24 python3 -c "
25import re
26config = open('${config}').read()
27pattern = r'\n\[Peer\]\n# ${name}\n[^\n]+\n[^\n]+\n'
28result = re.sub(pattern, '\n', config)
29open('${config}', 'w').write(result)
30"
31}
32