Thanks to visit codestin.com
Credit goes to github.com

Skip to content

jimmystridh/lazyshell

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LazyShell

LazyShell is a GPT powered utility for Zsh that helps you write and modify console commands using natural language. Perfect for those times when you can't remember the command line arguments for tar and ffmpeg, or when you just want to save time by having AI do the heavy lifting. The tool uses your current command line content (if any) as a base for your query, so you can issue modification requests for it. Invoke the completion with the default Ctrl+G shortcut; you still have to manually press enter to execute the suggested command.

LazyShell can also explain what the current command does. The explain widget ships unbound by default—set export LAZYSHELL_EXPLAIN_KEY='^E' in your shell config if you want to keep using Ctrl+E.

Screenshot

LazyShell is in alpha stage and may contain bugs. Currently only Zsh is supported.

How to use

Completion

  1. Hit the completion shortcut (Ctrl+G by default) to invoke the completion. The current command line content will be used as a base for your query.
  2. You can then write a natural language version of what you want to accomplish.
  3. Hit enter.
  4. The suggested command will be inserted into the command line.
  5. Hit enter to execute it, or continue modifying it.

Query examples for completion:

Unpack download.tar.gz

Start nginx server in docker
    Mount current dir

Speed up the video 2x using ffmpeg
    Remove audio track

Explanation

  1. Write down a command you want to understand.
  2. Bind the explain widget (for example export LAZYSHELL_EXPLAIN_KEY='^E') and hit that shortcut to invoke the explanation module.
  3. Hit any key to modify the command (the explanation will disappear).

Installation

LazyShell supports both OpenAI and Anthropic. Anthropic is the default provider; export LZSH_LLM_PROVIDER=openai if you want to switch.

# install prerequisites
brew install curl jq

# Download the script
curl -o ~/.lazyshell.zsh https://raw.githubusercontent.com/not-poma/lazyshell/master/lazyshell.zsh

# Add the following lines to your .zshrc
[ -f ~/.lazyshell.zsh ] && source ~/.lazyshell.zsh

After that restart your shell. You can invoke the completion with your configured shortcut and explanation with whatever key you bind.

Note: if you're on macOS and your terminal prints © when you press the hotkey, it means the OS intercepts the key combination first and you need to disable this behavior.

Configure API keys

LazyShell looks for API credentials in environment variables first and falls back to the macOS Keychain if they are missing. Generate keys from the OpenAI dashboard and the Anthropic console:

  • LZSH_OP_API_KEY (OpenAI)
  • LZSH_A_API_KEY (Anthropic)

macOS Keychain (recommended)

Store the secrets once and LazyShell will read them at shell startup:

security add-generic-password -a "$USER" -s lazyshell.openai -w '<openai-secret>' -U
security add-generic-password -a "$USER" -s lazyshell.anthropic -w '<anthropic-secret>' -U

Override the service or account names if you prefer different labels:

export LZSH_OPENAI_KEYCHAIN_SERVICE='my.openai.secret'
export LZSH_OPENAI_KEYCHAIN_ACCOUNT='custom-account'
export LZSH_ANTHROPIC_KEYCHAIN_SERVICE='my.anthropic.secret'
export LZSH_ANTHROPIC_KEYCHAIN_ACCOUNT='custom-account'

Environment variables

If you don't want to use the Keychain, export the secrets yourself before sourcing LazyShell:

export LZSH_OP_API_KEY='sk-...'
export LZSH_A_API_KEY='sk-ant-...'

Alternate Key Bindings

Configure shortcuts by exporting environment variables before sourcing LazyShell:

export LAZYSHELL_COMPLETE_KEY='^G'
export LAZYSHELL_EXPLAIN_KEY='^E'
export LAZYSHELL_TOGGLE_PROVIDER_KEY='^T'

Assign an empty string to disable a binding. Make sure your choices do not conflict with existing key bindings—check with bindkey -L if needed.

Contributing

This script is a crude hack, so any help is appreciated, especially if you can write zsh completion scripts. Feel free to open an issue or a pull request.

Inspired by https://github.com/TheR1D/shell_gpt

TODO

  • support for other shells
  • support keyboard interrupts
  • companion tool that explains the current command line contents
  • multiline formatting and syntax highlighting for the explanations
  • make some kind of preview before replacing the buffer
  • create brew package
  • query history
  • better json escaping
  • better error handling
  • token streaming
  • allow query editing while the previous one is in progress
  • maybe choose a better default shortcut?

About

AI powered Zsh completion script

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%