-
Notifications
You must be signed in to change notification settings - Fork 0
/
tryvimthemes.py
executable file
·57 lines (44 loc) · 1.48 KB
/
tryvimthemes.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
from __future__ import with_statement
from glob import glob
import os
import subprocess
import sys
import tarfile
import tempfile
THEME_PATHS = (
"/usr/share/vim/vim74/colors",
os.path.expanduser("~/.vim/colors"),
)
SAMPLE_ARCHIVE = "/usr/local/scripts/dat/samples.tar.gz"
SAMPLE_DIR_NAME = "samples"
THEME_LIST_NAME = "themes.txt"
if __name__ == "__main__":
if len(sys.argv) < 2:
commands = ["vim", "-p"]
else:
commands = sys.argv[1:]
themes = set()
for path in THEME_PATHS:
if os.path.isdir(path):
for dirname, dirs, files in os.walk(path):
for fn in files:
if fn.lower().endswith(".vim"):
themes.add(fn[:-4])
themes = list(themes)
themes.sort()
with tempfile.TemporaryDirectory(prefix="vim_themes_") as temp_dir:
os.chdir(temp_dir)
os.mkdir(SAMPLE_DIR_NAME)
with open(THEME_LIST_NAME, "w") as fh:
fh.write("\n".join(themes))
with tarfile.open(SAMPLE_ARCHIVE, "r") as tar_fh:
names = tar_fh.getnames()
for name in names:
if name.startswith("/") or name.startswith(".."):
print("Skipping %s, unsafe file name." % name)
continue
tar_fh.extract(name, path=SAMPLE_DIR_NAME)
commands.append(THEME_LIST_NAME)
commands += glob(os.path.join(SAMPLE_DIR_NAME, "*"))
subprocess.call(commands)