-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.py
executable file
·145 lines (125 loc) · 4.24 KB
/
install.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
143
144
145
#!/usr/bin/env python3
"""
# Install my dotfiles #
This installs my dotfiles for bash, Vim, MinTTy & Tmux, if & it finds
them. Backup files will be placed in ~/dotfile_backups+date
1. Create ~/dotfile_backup.YYYY-MM-DD_HHMM-SS
2. Copy any dot file it will replace into that directory
3. Replace or create .bash, .vim and .tmux rc files from the lists below
4. Run ~/dotfiles/tmux/plugin_install.sh to set up Tmux plug-ins
5. Run ~/dotfiles/vim/plugin_install.sh to set up Vim plug-ins
"""
import os
import platform
import subprocess
from datetime import datetime
COLOR = {
"red": "\u001b[31;1m",
"green": "\u001b[32;1m",
"yellow": "\u001b[33;1m",
"blue": "\u001b[34;1m",
"magenta": "\u001b[35;1m",
"cyan": "\u001b[36;1m",
"white": "\u001b[37;1m",
"reset": "\u001b[0m"
}
# Store starting directory and repo directory
HOME_DIR = os.environ['HOME']
START_PATH = (os.getcwd())
REPO_PATH = (os.path.dirname(os.path.realpath(__file__)))
# OS detection
OSTYPE = platform.system()
# Current date and time
NOW = datetime.now()
TIME_STAMP = NOW.strftime('%Y-%m-%d_%H:%M:%S')
# The dotfiles
BASH_FILES = [
'.bashrc',
'.bash_profile',
'.bash_prompt.sh',
'.LESS_TERMCAP'
]
MINTTY_FILES = [
'.minttyrc',
'.bash_mintty_colors'
]
VIM_FILES = [
'.vimrc',
'.gvimrc'
]
TMUX_FILES = [
'.tmux.conf',
'.tmux-syncoff.conf',
'.tmux-syncon.conf',
'.tmux.clipboard.conf',
'.tmux-status.conf'
]
# Backups
print(COLOR["cyan"] + '-------' + COLOR["reset"])
print(COLOR["cyan"] + 'Backups' + COLOR["reset"])
print(COLOR["cyan"] + '-------' + COLOR["reset"])
BACKUP_FILES = BASH_FILES + MINTTY_FILES + VIM_FILES + TMUX_FILES
BACKUP_DIRECTORY = HOME_DIR + '/dotfile_backup_' + TIME_STAMP
# Backing up existing dot files
os.mkdir(BACKUP_DIRECTORY)
for i in BACKUP_FILES:
CURRENT_FILE = HOME_DIR + '/' + i
if os.path.exists(CURRENT_FILE):
os.system('cp -v ' + CURRENT_FILE + ' ' + BACKUP_DIRECTORY)
print(' ')
#
# Bash
#
print(COLOR["cyan"] + '----' + COLOR["reset"])
print(COLOR["cyan"] + 'Bash' + COLOR["reset"])
print(COLOR["cyan"] + '----' + COLOR["reset"])
# Copying bash dot files
print(COLOR["green"] + 'Copying bash dot files' + COLOR["reset"])
for i in BASH_FILES:
os.system('cp -v ' + REPO_PATH + '/bash/' + i + ' ' + HOME_DIR + '/' + i)
print(' ')
# Copying tmux dot files
print(COLOR["cyan"] + '----' + COLOR["reset"])
print(COLOR["cyan"] + 'Tmux' + COLOR["reset"])
print(COLOR["cyan"] + '----' + COLOR["reset"])
TMUX_CHECK = subprocess.getstatusoutput('which tmux')
if TMUX_CHECK[0] == 0:
print(COLOR["green"] + 'Copying tmux dot files' + COLOR["reset"])
for i in TMUX_FILES:
os.system('cp -v ' + REPO_PATH + '/tmux/' + i + ' ' +
HOME_DIR + '/' + i)
print(' ')
print(COLOR["yellow"] + '** Reminder: Uncomment the appropriate block in ' +
HOME_DIR + '/.tmux.conf for clipboard integration' + COLOR["reset"])
# Install tmux plugins
print('Installing tmux plugins')
os.system('python3 ' + REPO_PATH + '/tmux/plugin_install.py')
print(' ')
# Tmux theme files for Linux vs WSL
COLOR_SCHEME = "airline_original"
if OSTYPE == 'Linux':
with open('/proc/version', 'r') as OSVER:
for line in OSVER:
if 'windows' in line.lower():
print('This is Widows Subsystem for Linux')
COLOR_SCHEME = "yellow"
else:
COLOR_SCHEME = "airline_original"
os.system('cp -v ' + REPO_PATH + '/tmux/themes/' + COLOR_SCHEME +
'/.tmux* ' + HOME_DIR + '/')
# Copying vim dot files
print(COLOR["cyan"] + '---' + COLOR["reset"])
print(COLOR["cyan"] + 'Vim' + COLOR["reset"])
print(COLOR["cyan"] + '---' + COLOR["reset"])
VIM_CHECK = subprocess.getstatusoutput('which vim')
if VIM_CHECK[0] == 0:
print(COLOR["green"] + 'Copying vim dot files' + COLOR["reset"])
for i in VIM_FILES:
os.system('cp -v ' + REPO_PATH + '/vim/' + i + ' ' +
HOME_DIR + '/' + i)
os.system(REPO_PATH + '/vim/plugin_install.py')
# Copying w3m dot files
W3M_CHECK = subprocess.getstatusoutput('which w3m')
if W3M_CHECK[0] == 0:
print(COLOR["green"] + 'Copying w3m dot file' + COLOR["reset"])
os.system('cp -vr' + REPO_PATH + '/w3m' + HOME_DIR)