3

GitHub - chinarjoshi/englizsh: Zsh plugin to interface command-line GPT programs...

 1 year ago
source link: https://github.com/chinarjoshi/englizsh
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

englizsh

A zsh plugin that defines 4 keybindings to intuitively interface with any command-line GPT program. The idea is to toggle the contents of the shell buffer between natural language and shell command and directly execute natural language using GPT as the translator.

Usage

  1. Control + Space: Toggles the buffer between English and command. Assumes the buffer contains a command if the first word is a valid command according to command -v.

Control+Space.mp4

  1. Alt + Space: Explicitly translates the buffer from English to command. Useful when the first word is a command, for instance when you're typing a command but forgot some flags.

Alt+Space.mp4

  1. Enter: Executes commands normally, but if command is not found and there appears to be English in the buffer, then it is translated to shell before executing.

Enter.mp4

  1. Control + Enter: Explicitly translates the buffer from English to command and executes it. Useful when you know you're executing English but it doesn't appear like it.

Control+Enter.mp4

Configuration

Englizsh can be configured through the following environmental variables before the script is sourced:

  • ENGLISH_TO_SHELL_CMD: Command that translates natural language to shell command. Default: sgpt --shell
  • SHELL_TO_ENGLISH_CMD: Command that translates shell command to natural language. Default: sgpt --describe-shell
  • ENGLIZSH_SAFE_CMD_NO_CONFIRM: If true, executes non-destructive commands without prompting for confirmation
  • ENGLIZSH_DEFAULT_EXECUTE: If true, entering nothing when prompted for confirmation executes the command by default
  • TOGGLE_BUFFER_KEYBINDING: Keycode for function 1. Default: ^@
  • TOGGLE_ENGLISH_KEYBINDING: Keycode for function 2. Default: ^[@
  • EXECUTE_ENGLISH_KEYBINDING: Keycode for function 4. Default: ^[[27;5;13~

Tip: If your GPT program does not already have options to produce or describe shell commands, you can use the following prompts:

English to shell prompt
Provide only {YOUR SHELL} commands for {YOUR OS} without any description. If there is a lack of details, provide most logical solution. Ensure the output is a valid shell command. If multiple steps required try to combine them together.

Shell to English prompt
Provide a terse, single sentence description of the given shell command. IMPORTANT: Do NOT start with 'This command ...', instead start with a verb. Use the following example: Command: du -cks Answer: List the total disk usage of the current directory and its subdirectories in kilobytes

Tip: To find the keycode for the keybinding you wish to use, enter Control + v in zsh followed by the keybinding.

Installation

Manually

  1. Download/update the script to ~/.englizsh with curl:

curl https://raw.githubusercontent.com/chinarjoshi/englizsh/main/englizsh > ~/.englizsh

  1. Source the script in your zshrc, assuming it is in your home directory.

echo '. ~/.englizsh' >> ~/.zshrc


Special thanks to @TheR1D for feedback while developing this.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK