forked from hitonanode/cplib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_snippet_conf.py
41 lines (35 loc) · 1.11 KB
/
generate_snippet_conf.py
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 python3
# "Config.txt" generator for "Clipboard History", snippet manager
# <https://blank-note.sakura.ne.jp/topics/clipboard_history.html>
import os
import re
rootdir = './'
config_header = [
'@NoteHotkey=Shift,400'
]
def read_hpp(filepath):
ret = [os.path.basename(filepath) + '|']
with open(filepath, 'r') as file:
for line in file.read().splitlines():
line = re.sub('([|`])', '`\\1', line)
ret.append('`' + line)
ret.append('/E')
return ret
def dfs(current_dir):
ret = list()
for ch in os.listdir(current_dir):
filepath = os.path.join(current_dir, ch)
if os.path.isdir(filepath):
ch_info = dfs(filepath)
if ch_info:
ret += ['+' + ch]
ret += ch_info
ret += ['..']
if os.path.isfile(filepath) and len(filepath) > 4 and filepath[-4:] == '.hpp':
ret += read_hpp(filepath)
return ret
if __name__ == '__main__':
ret = config_header + dfs(rootdir)
with open('Config.txt', 'w') as f:
for line in ret:
f.write(line + '\r\n')