Created
October 8, 2023 16:32
-
-
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 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 | |
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