forked from lukaszb/old-vimper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.py
143 lines (125 loc) · 5.53 KB
/
bootstrap.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python
from contrib import logger
from subprocess import Popen, PIPE
import datetime
import os
import shutil
import sys
abspath = lambda *p: os.path.abspath(os.path.join(*p))
now = datetime.datetime.now()
DATE_FORMAT = '%Y%m%d%H%M%S'
HOME_DIR = os.environ['HOME']
ROOT_DIR = abspath(os.path.dirname(__file__))
BUNDLE_DIR = abspath(ROOT_DIR, 'vim', 'bundle')
RUBY_BIN = '/usr/bin/ruby'
def setup_env():
if 'VIMPER_RUBY_BIN' in os.environ:
global RUBY_BIN
RUBY_BIN = os.environ['VIMPER_RUBY_BIN']
links = (
(abspath(ROOT_DIR, 'vim'), abspath(HOME_DIR, '.vim')),
(abspath(ROOT_DIR, 'vim/vimrc'), abspath(HOME_DIR, '.vimrc')),
(abspath(ROOT_DIR, 'vim/gvimrc'), abspath(HOME_DIR, '.gvimrc')),
)
def redefine_links():
# Create links and backup if needed
for src, dst in links:
if os.path.islink(dst):
orgpath = os.readlink(dst)
logger.debug("Found link: %s => %s" % (dst, orgpath))
os.remove(dst)
logger.warn("Removed link %s " % dst)
elif os.path.exists(dst):
newpath = '%s-%s' % (dst, now.strftime(DATE_FORMAT))
shutil.move(dst, newpath)
logger.debug("Moved %s to %s" % (dst, newpath))
else:
logger.debug("No entry at %s" % dst)
os.symlink(src, dst)
logger.info("Created link %s ==> %s" % (dst, src))
VIM_PLUGINS = {
'ack': 'git://github.com/vim-scripts/ack.vim.git',
'clojure': 'git://github.com/vim-scripts/VimClojure.git',
'closetag': 'git://github.com/vim-scripts/closetag.vim.git',
'cocoa': 'git://github.com/vim-scripts/cocoa.vim.git',
'coffee-script': 'git://github.com/kchmck/vim-coffee-script.git',
'color-sampler': 'git://github.com/vim-scripts/Color-Sampler-Pack.git',
'commandt': 'git://github.com/wincent/Command-T.git',
'ctrlp': 'git://github.com/kien/ctrlp.vim.git',
'easy-motion': 'git://github.com/vim-scripts/EasyMotion.git',
'fugitive': 'git://github.com/tpope/vim-fugitive.git',
'git': 'git://github.com/tpope/vim-git.git',
'gundo': 'http://github.com/sjl/gundo.vim.git',
'hemisu': 'git://github.com/noahfrederick/Hemisu.git',
'ir_black': 'git://github.com/lukaszb/vim-irblack.git',
'wombat256mod': 'git://github.com/michalbachowski/vim-wombat256mod.git',
'jedi': 'git://github.com/davidhalter/jedi-vim.git',
'jinja': 'git://github.com/vim-scripts/Jinja.git',
'jslint': 'git://github.com/hallettj/jslint.vim.git',
'matchit': 'https://github.com/vim-scripts/matchit.zip.git',
'nerdcommenter': 'git://github.com/scrooloose/nerdcommenter.git',
'nginx': 'git://github.com/vim-scripts/nginx.vim.git',
'nmap-syntax': 'git://github.com/vim-scripts/Nmap-syntax-highlight.git',
'mv-utils': 'git://github.com/MarcWeber/vim-addon-mw-utils.git',
'pyflakes': 'git://github.com/kevinw/pyflakes-vim.git',
'powerline': 'https://github.com/Lokaltog/vim-powerline.git',
'python-mode': 'git://github.com/klen/python-mode.git',
'selfdot': 'git://github.com/narfdotpl/selfdot.vim.git',
'singlecompile': 'git://github.com/xuhdev/SingleCompile.git',
'snipmate': 'git://github.com/garbas/vim-snipmate.git',
'snippets': 'git://github.com/honza/vim-snippets.git',
'solarized': 'git://github.com/altercation/vim-colors-solarized.git',
'superpy': 'git://github.com/lukaszb/superpy.git',
'supertab': 'git://github.com/ervandew/supertab.git',
'surround': 'git://github.com/tpope/vim-surround.git',
'syntastic': 'git://github.com/scrooloose/syntastic.git',
'taglist': 'git://github.com/vim-scripts/taglist.vim.git',
'tlib': 'git://github.com/tomtom/tlib_vim.git',
'yankring': 'git://github.com/vim-scripts/YankRing.vim.git',
'zoomwin': 'git://github.com/vim-scripts/ZoomWin.git',
'tagbar': 'git://github.com/vim-scripts/Tagbar.git',
'powerline': 'git://github.com/Lokaltog/vim-powerline.git',
}
# OSX Changes
if sys.platform == 'darwin':
pass
def run_cmd(cmd, stdout=None, stderr=None, cwd=None, shell=None):
if stdout is None:
stdout = sys.stdout
if stderr is None:
stderr = sys.stderr
if shell is None:
shell = True
p = Popen(cmd, shell=True, cwd=cwd, stdout=stdout, stderr=stderr)
return p.communicate()
def get_plugin(name, uri):
dst = abspath(BUNDLE_DIR, name)
# Git repo
if uri.endswith('git'):
if os.path.isdir(dst) and os.path.isdir(abspath(dst, '.git')):
# Update git repo (git pull)
logger.debug("Fetching %s => %s" % (uri, dst))
run_cmd('git pull origin master', cwd=dst)
else:
logger.debug("Cloning %s => %s" % (uri, dst))
run_cmd('git clone --recursive %s %s' % (uri, dst))
def post_actions():
# Command-T
COMMANDT_DIR = abspath(BUNDLE_DIR, 'commandt')
src_dir = abspath(COMMANDT_DIR, 'ruby', 'command-t')
cmd = '%s extconf.rb' % RUBY_BIN
run_cmd(cmd, cwd=src_dir, stdout=PIPE, stderr=PIPE)
run_cmd('make clean && make', cwd=COMMANDT_DIR)
def main():
# Prepare
setup_env()
redefine_links()
backupdir = abspath(HOME_DIR, '.vim/', 'backup')
if not os.path.isdir(backupdir):
os.makedirs(backupdir)
# Fetch plugins
for name, uri in VIM_PLUGINS.iteritems():
get_plugin(name, uri)
post_actions()
if __name__ == '__main__':
main()