forked from Kirti-Rathi/PromptShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (58 loc) · 2.73 KB
/
main.py
File metadata and controls
71 lines (58 loc) · 2.73 KB
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
from .ai_terminal_assistant import AITerminalAssistant
from .readline_setup import setup_readline
import platform
import os
from .ansi_support import enable_ansi_support
from .format_utils import format_text, reset_format, get_terminal_size
from .setup import setup_wizard, load_config, get_active_model
def main():
config = load_config()
if not config:
print("First-time setup required!")
setup_wizard()
config = load_config()
enable_ansi_support()
setup_readline()
model_name = get_active_model()
assistant = AITerminalAssistant(config=config, model_name=model_name)
print(f"""\n{format_text('green', bold=True)}Welcome to the AI-Powered Terminal Assistant!
Active provider: ({model_name} - {platform.system()})
Type '--help' for assistance and '--config' for settings.{reset_format()}""")
while True:
try:
columns, _ = get_terminal_size()
prompt = f"\n{format_text('green', bold=True)}{os.getcwd()}$ {reset_format()}"
user_input = input(prompt)
if len(prompt) + len(user_input) > columns:
print() # Move to the next line if input is too long
if user_input.lower() == 'quit':
print(format_text('red', bold=True) + "\nTerminating..." + reset_format())
break
if user_input.lower() == "--config":
setup_wizard()
config = load_config()
model_name = get_active_model()
assistant = AITerminalAssistant(config=config, model_name=model_name)
print(f"{format_text('yellow', bold=True)}Configuration updated!{reset_format()}")
continue
if user_input.lower() == "--help":
print(f"""{format_text('blue')}- You can use natural language queries or standard shell commands.
- Start your input with '!' to execute a command directly without processing.
- Start or end your input with '?' to ask a question.
- Tab completion for files and folders is enabled.
- Use 'Ctrl + c' or type 'quit' to quit the assistant.
- Type 'clear' to clear the terminal.{reset_format()}""")
continue
# ✅ Handle alias command
if user_input.lower().startswith("alias "):
result = handle_alias_command(user_input, assistant.alias_manager)
print(result)
continue
# All other commands (including dangerous ones) are handled by the assistant
result = assistant.execute_command(user_input)
print(result)
except KeyboardInterrupt:
print(format_text('red', bold=True) + "\nTerminating..." + reset_format())
break
if __name__ == "__main__":
main()