forked from drmikehenry/vimfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·61 lines (43 loc) · 1.21 KB
/
setup.py
File metadata and controls
executable file
·61 lines (43 loc) · 1.21 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
54
55
56
57
58
59
60
61
#!/usr/bin/env python
from __future__ import print_function
import os
import re
import subprocess
class RunError(Exception):
pass
def run_args_out_err(args):
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
return out, err
def run_args(args):
out, err = run_args_out_err(args)
if err:
raise RunError('%s' % str(args))
return out
def join_lines(lines):
return ''.join([line + '\n' for line in lines])
def read_lines(path):
f = open(path, 'r')
lines = f.read().splitlines()
f.close()
return lines
def write_lines(path, lines):
f = open(path, 'w')
f.write(join_lines(lines))
f.close()
def main():
home_path = os.path.expanduser('~')
vimrc_path = os.path.join(home_path, '.vimrc')
if os.path.isfile(vimrc_path):
vimrc_lines = read_lines(vimrc_path)
else:
vimrc_lines = []
runtime_line = 'runtime vimrc'
for line in vimrc_lines:
if re.match(r'(\s*"\s*)?' + re.escape(runtime_line) + r'\s*$', line):
break
else:
vimrc_lines.insert(0, runtime_line)
write_lines(vimrc_path, vimrc_lines)
if __name__ == '__main__':
main()