A powerfully simple tool for your CLI. Send your last commands to an LLM and get instant help!
Basic example:
lew.mp4
LEW will also request to run commands to further support your request.
2024-03-29_11-01-01.mp4
Use LEW to quickly navigate AWS.
2024-03-29_16-21-47.mp4
I will have a blog post up soon at davidlozzi.com
- Only works in iTerm2, doesn't work in VSCode terminal or other terminals where iTerm2 isn't in use.
- Will not work when SSH'd into another server.
- If a command run by lew is prompting for user input, you will not see it. Cancel the job and run the command manually.
The current state of the utility is great, it has helped me a few times already. But there is more I want it to do:
in no particular order
- Switch to Anthropic just to check it out
- Improve logging capture, remove need for iTerm2 (attempted with ZSH natively)
- Allow user to specify which commands to send, instead of starting from the last command, i.e. send commands 2 and 3 I ran, not the immediate last one.
- Explore how to support when SSH'd in another server (is it as simple as following steps below except for the iTerm2 steps?)
- Create an easier install/setup script
- Currently the script only looks at the last log file, expand it to treat all logs as it's "db"
- Support Bash, PowerShell, Windows Command, and whatever else.
Allow the LLM to provide updated commands and enable the user to run themSend contents of a file as desired to the LLM
To get started, you'll need:
- Python v3 or later
- iTerm2 installed on your Mac
- You can add the config
"terminal.external.osxExec": "iTerm.app"
to your VSCodesettings.json
file to use iTerm in VScode.
- You can add the config
- Clone this repo to your local machine
- Run
pip install -r requirements.txt
to install dependencies.
- Run
- Copy the
.env.sample
file to.env
(it will be ignored by git) - Get your OpenAI API Key from openai.com and update
.env
with your key.
-
Open iTerm2 (prereqs #2), go to Settings
- In Settings, go to Profiles, then select your profile on the left (probably Default)
- Go to Session on the right.
- Under Miscellaneous, check to enable Automatically log session input to files in:
- Also check to enable Log plain text on the right
- Click the Change button
- Currently, the code looks in
~/iterm2_logs/
for the logs from iTerm2.-
Create a folder in the root called
iterm2_logs
and select thator
-
Create a folder where ever you want, and update the variable
ITERM2_LOGS
in.env
-
- Update your cli logging delimiter:
- In iTerm2, you'll see your cli command prompt prefix, usually something like username@machinename, i.e.
david.lozzi@KHH9RGC0WN
on my machine. Copy that value. - Edit the
.env
file and set yourCLI_LOG_DELIMITER
value.
- In iTerm2, you'll see your cli command prompt prefix, usually something like username@machinename, i.e.
-
Edit your
~/.zshrc
file, you can do this by:- If you have VSCode in your cli, enter
code ~/.zshrc
- If you like vim, enter
vim ~/.zshrc
- Or
open ~/
, then in Finder, pressCMD+SHIFT+.
to view hidden files then open the file in your editor of choice.
- If you have VSCode in your cli, enter
-
Add the following line:
alias lew="python ~/git/lew-llm-cli/app/command.py"
- Update the location of the
command.py
file (prereqs #3)
- Update the location of the
- The python script
command.py
will clean up theiterm2_logs
folder automatically, keeping only the last 7 days - This script itself writes to
~/lew.log
and will only keep the last 7 days of logs.
Real simple, after an error or command run, just enter lew
and hit enter!
More detail:
lew "message to include" --cnt 2
"message to include"
, optional (default is empty), is a message you'd like to send along with the last command(s). You can explain what you're doing or whatever it is you need.--cnt 2
, optional (default is 1), allows you to include more than 1 command and output to GPT, if you wanted to include the last 2 or more commands and their output, set thecnt
parameter. You may also setcnt
to0
to have a chat with the bot without sending a command.
Help with a git command
❯ git status
fatal: not a git repository (or any of the parent directories): .git
❯ lew
Calling GPT to get your answer...
The error message you're seeing, `fatal: not a git repository (or any of the parent directories): .git`, indicates that....
Troubleshooting a specific file
lew "my package file is messing up" --cnt 0 ─╯
Calling GPT to get your answer...
To help you effectively, I need to know which package file you're referring to and what specific issue you're encountering. If it's a `package.json` for a Node.js project, or a different package file for another language or framework, please specify. Additionally, running a command that shows the error or problem you're facing with the package file can greatly help in diagnosing the issue.
If you can, please run the command that leads to the error, and then use:
---
lew --cnt 2
---
to send me the command along with its output. If it's an issue with the content of the package file itself, consider running:
---
cat path/to/packagefile
---
And then:
---
lew --cnt 2
---
to show me the contents of the file.%
Chat without sending the last command
lew "how do i list my director?" --cnt 0
Calling GPT to get your answer...
To list the contents of your current directory, please run the following command:
---
ls
---
This will show you all the files and directories in your current working directory.%
Some common things I've run into:
Failed to call the API: 401
- make sure your API key is correct.- Running
lew
responds to another command, not your last one. Are you running your current command iniTerm2
? Can you see your command and output in theiterm2_logs
folder you configured?
If you have other issues, post an Issue here.
I love contributions from everyone. Go ahead and Fork the repository, perform your work, and then post a PR.