Last active
October 21, 2024 23:27
-
-
Save madacol/2e8e2f5e22b03bfe4f22fbe30dd9c978 to your computer and use it in GitHub Desktop.
zsh script, that ask `llm` for a shell command, and puts it in the edit buffer, ready to execute or edit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/zsh | |
| # This script needs to be sourced in a zsh shell instead of being executed | |
| # To do so, set an alias in your shell: | |
| # alias '??'='source $HOME/.local/bin/nlsh.zsh' | |
| # Then you can use the `??` command from any zsh shell like this: | |
| # ?? extract the content of ./file.zip in the current directory | |
| echo "$@" \ | |
| | llm -s 'Your task is to output oneliner shell commands. | |
| Always answer with a single line shell command, or a multiline using code blocks' \ | |
| | tee /dev/shm/nlsh_stdout | |
| extracted_command=$(sed -n '/^[ \t]*```/,/^[ \t]*```/{//!p}' /dev/shm/nlsh_stdout) | |
| # If the command is empty, get the last line of the output | |
| if [ -z "$extracted_command" ]; then | |
| extracted_command=$(tail -n 1 /dev/shm/nlsh_stdout) | |
| fi | |
| print -rz $extracted_command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment