Skip to content

Commit 2db7217

Browse files
committed
improve prompt and follow directory changes
1 parent 5a6c003 commit 2db7217

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Need to Google that command you can't quite remember? Use a Large Language Model
66
* Just describe what you want to do and the LLM will generate the commands for you.
77
* You can be vague, you will be prompted for parameter details (file and folder names, branches, commit messages etc)
88

9-
<img width="621" alt="example" src="https://user-images.githubusercontent.com/368013/232493882-6bb8b4f8-6988-41f1-9f25-a1685e0c1750.png">
9+
<img width="623" alt="example" src="https://user-images.githubusercontent.com/368013/232639264-cd136de1-a1cd-4e32-ba39-ee860793d9de.png">
1010

1111
## Installation
1212

src/llm-cli.cr

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ rescue error : LLM::CLI::Chat::Error
1818
end
1919
shell = LLM::CLI::Shell.new
2020
prompt = LLM::CLI::Prompt.new({
21-
"No user assistance",
21+
"No user assistance, command ordering is important",
22+
"You are running on #{shell.operating_system}",
2223
"Commands to be executed on the following shell: #{File.basename shell.selected}",
2324
"Wrap unknown command parameters in <brackets>",
25+
"you might need to change directory before executing subsequent commands",
2426
})
2527

2628
# grab the users request
@@ -99,6 +101,21 @@ begin
99101
error: :inherit
100102
).wait
101103
puts "Command failed with exit code: #{status.exit_code}" unless status.success?
104+
105+
# change directory as required
106+
if execute.starts_with?("cd ") || execute.includes?("&& cd ")
107+
args = Process.parse_arguments(execute)
108+
found = nil
109+
args.each_with_index do |cmd, index|
110+
if cmd == "cd"
111+
found = index + 1
112+
break
113+
end
114+
end
115+
if found && (new_dir = args[found]?)
116+
Dir.cd(new_dir)
117+
end
118+
end
102119
end
103120
end
104121
rescue error

src/llm-cli/shell.cr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ class LLM::CLI::Shell
2222
shell
2323
end
2424

25+
{% begin %}
26+
def operating_system
27+
{% if flag?(:win32) %}
28+
"windows"
29+
{% elsif flag?(:darwin) %}
30+
"macOS"
31+
{% elsif flag?(:musl) %}
32+
"musl linux"
33+
{% elsif flag?(:linux) %}
34+
"linux"
35+
{% elsif flag?(:bsd) %}
36+
"bsd"
37+
{% else %}
38+
"posix"
39+
{% end %}
40+
end
41+
{% end %}
42+
2543
def get_input(prompt)
2644
print prompt
2745
STDIN.gets.to_s.chomp

0 commit comments

Comments
 (0)