forked from mathiasbynens/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-ohmyzsh.py
176 lines (163 loc) · 5.58 KB
/
config-ohmyzsh.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python3
import os
import subprocess
import shutil
import argparse
from pathlib import Path
def is_github_reachable():
try:
response = subprocess.check_output(
["curl", "-Is", "https://raw.githubusercontent.com"],
stderr=subprocess.STDOUT,
)
return "200" in response.decode("utf-8").split("\n")[0]
except subprocess.CalledProcessError:
return False
def main(use_github):
if not Path("./sources").is_dir():
print("please execute this script in the dotfiles directory")
exit(1)
# check if git , curl is installed
if shutil.which("git") is None:
print("git is not installed")
exit(1)
if shutil.which("curl") is None:
print("curl is not installed")
exit(1)
github_reachable = is_github_reachable() if use_github else False
if github_reachable:
print("github is reachable")
else:
print("github is not reachable")
print("Using local scripts / gitee .")
print("update submodules")
subprocess.run(["git", "submodule", "init"])
subprocess.run(["git", "submodule", "update"])
oh_my_zsh_path = Path.home() / ".oh-my-zsh" / "oh-my-zsh.sh"
if oh_my_zsh_path.is_file():
print("oh-my-zsh is already installed")
else:
oh_my_zsh_dir = Path.home() / ".oh-my-zsh"
if oh_my_zsh_dir.is_dir():
print("oh-my-zsh was inistalled")
print("backing up omz dir")
shutil.rmtree(Path.home() / "oh-my-zsh.bkp", ignore_errors=True)
shutil.move(str(oh_my_zsh_dir), str(Path.home() / "oh-my-zsh.bkp"))
else:
print("oh-my-zsh is not installed")
print("installing oh-my-zsh")
install_url = (
"https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh"
if not github_reachable
else "https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh"
)
subprocess.run(["curl", "-fsSL", install_url, "-o", "./install.sh"])
# os.environ["RUNZSH"] = "no"
# os.environ["CHSH"] = "no"
subprocess.run(["sh", "./install.sh"])
# del os.environ["RUNZSH"]
# del os.environ["CHSH"]
Path("./install.sh").unlink()
# plugins managed by antigen
print("installing antigen")
subprocess.run(
[
"curl",
"-fsSL",
"https://gitee.com/romkatv/antigen/raw/master/bin/antigen.zsh",
"-o",
str(Path.home() / "antigen.zsh"),
]
)
# print(
# "installing powerlevel10k and zsh-autosuggestions and zsh-syntax-highlighting"
# )
# if not github_reachable:
# print(
# "installing powerlevel10k zsh-autosuggestions, zsh-syntax-highlighting from gitee"
# )
# subprocess.run(
# [
# "git",
# "clone",
# "--depth=1",
# "https://gitee.com/romkatv/powerlevel10k.git",
# str(Path.home() / ".oh-my-zsh/custom/themes/powerlevel10k"),
# ]
# )
# subprocess.run(
# [
# "git",
# "clone",
# "--depth=1",
# "https://gitee.com/githubClone/zsh-autosuggestions.git",
# str(Path.home() / ".oh-my-zsh/custom/plugins/zsh-autosuggestions"),
# ]
# )
# subprocess.run(
# [
# "git",
# "clone",
# "--depth=1",
# "https://gitee.com/yuxiaoxi/zsh-syntax-highlighting",
# str(Path.home() / ".oh-my-zsh/custom/plugins/zsh-syntax-highlighting"),
# ]
# )
# else:
# print(
# "installing powerlevel10k zsh-autosuggestions, zsh-syntax-highlighting from github"
# )
# subprocess.run(
# [
# "git",
# "clone",
# "--depth=1",
# "https://github.com/romkatv/powerlevel10k.git",
# str(Path.home() / ".oh-my-zsh/custom/themes/powerlevel10k"),
# ]
# )
# subprocess.run(
# [
# "git",
# "clone",
# "--depth=1",
# "https://github.com/zsh-users/zsh-autosuggestions",
# str(Path.home() / ".oh-my-zsh/custom/plugins/zsh-autosuggestions"),
# ]
# )
# subprocess.run(
# [
# "git",
# "clone",
# "--depth=1",
# "https://github.com/zsh-users/zsh-syntax-highlighting.git",
# str(Path.home() / ".oh-my-zsh/custom/plugins/zsh-syntax-highlighting"),
# ]
# )
print("copying config")
shutil.copyfile(
"./sources/zsh_plugins/zsh-autosuggestions.plugin.zsh",
str(
Path.home()
/ ".oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh"
),
)
shutil.copyfile(
"./sources/zsh_plugins/zsh-syntax-highlighting.plugin.zsh",
str(
Path.home()
/ ".oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh"
),
)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Configure oh-my-zsh with optional GitHub usage."
)
parser.add_argument(
"--use_github",
type=bool,
default=True,
help="Use GitHub for installation (default: True)",
)
args = parser.parse_args()
main(args.use_github)