-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-oh-my-zsh.py
executable file
·85 lines (59 loc) · 2.02 KB
/
remove-oh-my-zsh.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
#!/bin/python3
import os
import sys
import re
USER = os.environ.get("SUDO_USER")
HOME = f'/home/{USER}'
RED = "\033[31m"
ZSHRC = f'{HOME}/.zshrc'
def remove_omz_directory():
omz_dir = f'{HOME}/.oh-my-zsh'
try:
os.system(f'rm -rf {omz_dir}')
except Exception:
print(f"\n{RED} Failed on remove .oh-my-zsh directory! \n")
def remove_pre_omz_file():
pre_omz_file = f'{HOME}/.zshrc.pre-oh-my-zsh'
try:
os.system(f'rm -rf {pre_omz_file}')
except Exception:
print(f"\n{RED} Failed on remove .zshrc.pre-oh-my-zsh file! \n")
def remove_lines_from_zshrc():
try:
lines_list = [line.rstrip() for line in open('oh-my-zsh-template.txt')]
zshrc_new_file = []
with open(ZSHRC, 'r') as zshrc_file:
for line in zshrc_file.readlines():
actual_line = line.rstrip()
if(not actual_line in lines_list):
zshrc_new_file.append(actual_line + '\n')
new_file = open(ZSHRC, 'w', encoding='utf-8')
new_file.writelines(zshrc_new_file)
new_file.close()
except Exception:
print(f"\n{RED} Failed on remove some lines of .zshrc file! \n")
def remove_diferent_lines():
try:
pattern = 'ZSH_THEME'
zshrc_new_file = []
with open(ZSHRC, 'r') as zshrc_file:
for line in zshrc_file.readlines():
actual_line = line.rstrip()
if(not re.search(pattern, actual_line)):
zshrc_new_file.append(actual_line + '\n')
new_file = open(ZSHRC, 'w', encoding='utf-8')
new_file.writelines(zshrc_new_file)
new_file.close()
except Exception:
print(f"\n{RED} Failed on remove some lines of .zshrc file! \n")
def main():
remove_omz_directory()
remove_pre_omz_file()
remove_lines_from_zshrc()
remove_diferent_lines()
if __name__ == '__main__':
user_type = os.getuid()
if(user_type != 0):
print(f"\n{RED} Please Run as Root! \n")
sys.exit(1)
main()