@@ -110,6 +110,7 @@ def install_config() -> None:
110
110
def append_to_shell_profile (line ):
111
111
"""
112
112
Append a line to the appropriate shell profile file (.zshrc or .bashrc).
113
+ Asks for confirmation before modifying any files.
113
114
114
115
Args:
115
116
line (str): The line to append to the shell profile.
@@ -120,10 +121,28 @@ def append_to_shell_profile(line):
120
121
else :
121
122
profile_file = os .path .expanduser ("~/.bashrc" )
122
123
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 } " )
127
146
128
147
129
148
def load_config () -> Dict [str , Any ]:
0 commit comments