Nelson is a Unix Command Line Tool written in Bash that allows for AI suggestions, error explanations, and more, all straight from the terminal. Currently using OpenAI API (because that's what I know), planning to move into an open source, local LLM in the future.
This tool uses OpenAI's ChatGPT models to generate responses via their API. In order to use this tool, you need to have a valid API key. If you want to test out the tool, feel free to send me a message on Discord @sawsent , I might be able to provide one.
git clone https://github.com/sawsent/nelson.git
# .zshrc / .bashrc / .profile / ...
export OPENAI_API_KEY="your-openai-key"
export NELSON_LOCATION="path/to/nelson"
alias nelson="$NELSON_LOCATION/src/main.sh"
Step 3: Change shell HISTFILE in settings.sh
- Find out where you Command History file is located
echo $HISTFILE
# My output: /Users/vicente.figueiredo/.zhistory
- Replace in settings.sh
# setings.sh
# because we're using bash to run the script, it might be different than your main zsh or fish $HISTFILE (I think)
export HISTFILE="/Users/vicente.figueiredo/.zhistory" # <- replace with your $HISTFILE
You need to source your shell config file to access $NELSON_LOCATION
chmod +x $NELSON_LOCATION/src/main.sh
You can use this tool for as many reasons as you want. It's very easy to extend the functionality with custom system prompts and/or aliases.
- Choose the model you want to use for the specific request (ex:
--model=gpt-4o
) - Choose temperature you want to use (ex:
--temp=0.5
) - Choose the max tokens you want to use (ex:
--max-tokens=100
) - Choose the mode (System Prompt) to use with
--\<mode>
- NEW: Choose a one-time System Prompt with
--system-prompt="Custom Prompt"
- NEW: Ask nelson to explain the last error with
nelson --wtf
- You can obviously change all defaults (see settings.sh)
- Commands run and OpenAI responses (the whole JSON response) can be stored in an history.log file
(i didn't check if nelson was right btw, and Im using bat with some style opts for the output (see settings.sh))
- --neat (-n): Answers in the most concise way possible
- --long (-l): Explains in more detail
- --code (-c): Simply codes what's requested. No comments and no explanations
- --command (-com): Provides a Shell command based on the given parameters NEW: copy the command to the clipboard with a single click!
You can ask for clarification on your last command run by simply running nelson --wtf
.
You can easily change defaults, how the code is printed to the terminal in settings.sh.
You can also easily add more modes (System Prompts) in the system_prompts.sh. Simply follow the pattern that's already there!
case $1 in
default)
echo "$DEFAULT_SYSTEM_PROMPT"
;;
# ...
# ...
your-custom-mode)
echo "Your Custom System Prompt"
;;
# ...
Once you do that, it will immediatly be available to use!
nelson --your-custom-mode Your question for nelson
(Keep in mind, you cant use any names that have already been defined as flags like --debug, --max-temperature, etc...). These take precedence in the flag hierarchy (they're evaluated first in the case block)
- Add A Way to override system prompts directly in the command line: Instead of having to modify system_prompts.sh, you can simply do
nelson --system-prompt="Custom System Prompt" question
for occasional System Prompt needs. - Add Context Support (ex:
nelson --explain-error
/nelson --wtf
): Automatically sends the last command run and the output for nelson to explain. - Migrate / add support for locally-hosted LLMs (like Llama): I have an API key because I put 10€ on a project once, but not everyone does so it would be better if you could use other APIs and self-hosted LLMs.