-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_symlinks.py
138 lines (118 loc) · 5.52 KB
/
create_symlinks.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
import os
import shutil
import subprocess
import platform
# Terminal colors
RED = '\033[91m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
RESET = '\033[0m'
def get_user_confirmation(message):
while True:
user_input = input(f"{YELLOW}{message} (y/n) {RESET}").lower()
if user_input in ['y', 'n']:
return user_input == 'y'
else:
print(f"{RED}Invalid input. Please enter 'y' or 'n'.{RESET}")
def create_symlink(source, destination):
if get_user_confirmation(f"Do you want to create a symlink for {source}?"):
print(f"{YELLOW}Creating symlink for {source}{RESET}")
if os.path.exists(destination):
print(f"{BLUE}Backup existing {destination} file{RESET}")
backup_dir = os.path.expanduser('~/dotfiles_backup')
if not os.path.exists(backup_dir):
os.mkdir(backup_dir)
shutil.move(destination, os.path.join(backup_dir, os.path.basename(destination)))
os.symlink(source, destination)
print(f"{GREEN}Symlink created for {source}{RESET}")
else:
print(f"{YELLOW}Skipping symlink creation for {source}{RESET}")
def install_neovim():
if get_user_confirmation("Do you want to attempt installing Neovim?"):
print(f"{YELLOW}Detecting OS to install Neovim{RESET}")
os_type = platform.system()
if os_type == "Linux":
print(f"{BLUE}Updating package list and installing Neovim on Linux{RESET}")
try:
subprocess.run(["sudo", "apt", "update"], check=True)
subprocess.run(["sudo", "apt", "install", "neovim"], check=True)
print(f"{GREEN}Neovim installed successfully{RESET}")
except subprocess.CalledProcessError as e:
print(f"{RED}Failed installing Neovim. Error: {e}{RESET}")
elif os_type == "Darwin":
print(f"{BLUE}Installing Neovim on macOS{RESET}")
try:
subprocess.run(["brew", "install", "neovim"], check=True)
print(f"{GREEN}Neovim installed successfully{RESET}")
except subprocess.CalledProcessError as e:
print(f"{RED}Failed installing Neovim. Error: {e}{RESET}")
else:
print(f"{RED}Unsupported OS: {os_type}{RESET}")
return
print(f"{YELLOW}Setting up Neovim configuration{RESET}")
nvim_config_dir = os.path.expanduser('~/.config/nvim')
if not os.path.exists(nvim_config_dir):
os.makedirs(nvim_config_dir)
init_vim_source = os.path.expanduser('~/dotfiles/init.vim')
init_vim_dest = os.path.expanduser('~/.config/nvim/init.vim')
create_symlink_for_init_vim = get_user_confirmation("Do you want to create a symlink for init.vim?")
if create_symlink_for_init_vim:
create_symlink(init_vim_source, init_vim_dest)
else:
print(f"{YELLOW}Skipping Neovim installation{RESET}")
init_vim_source = os.path.expanduser('~/dotfiles/init.vim')
init_vim_dest = os.path.expanduser('~/.config/nvim/init.vim')
create_symlink_for_init_vim = get_user_confirmation("Do you still want to create a symlink for init.vim?")
if create_symlink_for_init_vim:
nvim_config_dir = os.path.expanduser('~/.config/nvim')
if not os.path.exists(nvim_config_dir):
os.makedirs(nvim_config_dir)
create_symlink(init_vim_source, init_vim_dest)
def install_ohmyzsh_plugins():
if get_user_confirmation("Do you want to install Oh My Zsh plugins?"):
print(f"{YELLOW}Installing Oh My Zsh plugins{RESET}")
zsh_custom_dir = os.path.expanduser(os.environ.get('ZSH_CUSTOM', '~/.oh-my-zsh/custom'))
# List of plugins and their git URLs
plugins = {
'zsh-autosuggestions': 'https://github.com/zsh-users/zsh-autosuggestions.git',
'zsh-syntax-highlighting': 'https://github.com/zsh-users/zsh-syntax-highlighting.git'
}
# List of themes and their git URLs
themes = {
'powerlevel10k': 'https://github.com/romkatv/powerlevel10k.git'
}
# Install plugins
for plugin, url in plugins.items():
plugin_dir = f"{zsh_custom_dir}/plugins/{plugin}"
if not os.path.exists(plugin_dir):
print(f"{BLUE}Installing {plugin}{RESET}")
subprocess.run(["git", "clone", url, plugin_dir])
print(f"{GREEN}{plugin} installed{RESET}")
else:
print(f"{GREEN}{plugin} already exists{RESET}")
# Install themes
for theme, url in themes.items():
theme_dir = f"{zsh_custom_dir}/themes/{theme}"
if not os.path.exists(theme_dir):
print(f"{BLUE}Installing {theme}{RESET}")
subprocess.run(["git", "clone", "--depth=1", url, theme_dir])
print(f"{GREEN}{theme} installed{RESET}")
else:
print(f"{GREEN}{theme} already exists{RESET}")
else:
print(f"{YELLOW}Skipping Oh My Zsh plugin installation{RESET}")
print(f"{YELLOW}=== Starting Automated Setup ==={RESET}")
config_mapping = {
'bashrc': '~/.bashrc',
'zshrc': '~/.zshrc',
'p10k.zsh': '~/.p10k.zsh',
}
if __name__ == "__main__":
for source, dest in config_mapping.items():
src_path = os.path.expanduser(f'~/dotfiles/{source}')
dest_path = os.path.expanduser(dest)
create_symlink(src_path, dest_path)
install_neovim()
install_ohmyzsh_plugins()
print(f"{GREEN}=== Setup Complete ==={RESET}")