Skip to content

Commit fa32ccd

Browse files
authored
Fix: Ask for confirmation before modifying shell profile files (fixes #14) (#18)
1 parent 4ba386c commit fa32ccd

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

transcribe_me/config/config_manager.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def install_config() -> None:
110110
def append_to_shell_profile(line):
111111
"""
112112
Append a line to the appropriate shell profile file (.zshrc or .bashrc).
113+
Asks for confirmation before modifying any files.
113114
114115
Args:
115116
line (str): The line to append to the shell profile.
@@ -120,10 +121,28 @@ def append_to_shell_profile(line):
120121
else:
121122
profile_file = os.path.expanduser("~/.bashrc")
122123

123-
with open(profile_file, "a") as f:
124-
f.write(f"\n{line}\n")
125-
126-
print(f"{Fore.GREEN}API key added to {profile_file}")
124+
# Ask for confirmation before modifying the shell profile
125+
print(f"{Fore.YELLOW}Would you like to add the API key to your {profile_file}?")
126+
print(f"{Fore.YELLOW}This will append the following line: {line}")
127+
confirmation = input(f"{Fore.CYAN}Add to shell profile? (y/N): ").lower()
128+
129+
if confirmation == 'y' or confirmation == 'yes':
130+
try:
131+
with open(profile_file, "a") as f:
132+
f.write(f"\n{line}\n")
133+
print(f"{Fore.GREEN}API key added to {profile_file}")
134+
except PermissionError:
135+
print(f"{Fore.RED}Permission denied when trying to write to {profile_file}")
136+
print(f"{Fore.YELLOW}You may need to add the API key manually:")
137+
print(f"{Fore.YELLOW}{line}")
138+
except Exception as e:
139+
print(f"{Fore.RED}Error writing to {profile_file}: {e}")
140+
print(f"{Fore.YELLOW}You may need to add the API key manually:")
141+
print(f"{Fore.YELLOW}{line}")
142+
else:
143+
print(f"{Fore.YELLOW}Skipped adding API key to shell profile.")
144+
print(f"{Fore.YELLOW}Remember to set the environment variable manually:")
145+
print(f"{Fore.YELLOW}{line}")
127146

128147

129148
def load_config() -> Dict[str, Any]:

0 commit comments

Comments
 (0)