-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.py
62 lines (43 loc) · 1.68 KB
/
configure.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
import os
import subprocess
BLUE = "\033[94m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RESET = "\033[0m"
def set_git_config(key, value):
if value:
subprocess.run(["git", "config", "--global", key, value], check=True)
print(f"{GREEN}Set {key} to '{value}'{RESET}")
else:
print(f"{YELLOW}Skipped setting {key} (no value){RESET}")
def prompt_user_input(prompt_message, default_value=None):
prompt_message = f"{BLUE}{prompt_message}"
if default_value:
prompt_message += f" [{default_value}]: {RESET}"
else:
prompt_message += f": {RESET}"
user_input = input(prompt_message).strip()
return user_input if user_input else default_value
def prompt_yes_no(question):
while True:
answer = input(f"{BLUE}{question} (y/n): {RESET}").strip().lower()
if answer in ["y", "n"]:
return answer == "y"
print(f"{YELLOW}Invalid input. Please enter 'y' or 'n'.{RESET}")
def configure_git_user():
print(f"{BLUE}Configuring git user settings...{RESET}")
git_username = prompt_user_input("Enter your Git username")
git_email = prompt_user_input("Enter your Git email")
set_git_config("core.editor", "vim")
set_git_config("gpg.program", "/opt/homebrew/bin/gpg")
set_git_config("commit.gpgsign", "true")
set_git_config("tag.gpgsign", "true")
set_git_config("init.defaultBranch", "main")
set_git_config("user.name", git_username)
set_git_config("user.email", git_email)
def main():
if prompt_yes_no("Do you want to configure your git user settings?"):
configure_git_user()
print(f"{GREEN}User configuration completed.{RESET}")
if __name__ == "__main__":
main()