Skip to content

Instantly share code, notes, and snippets.

@madacol
Created October 8, 2023 16:32
Show Gist options
  • Save madacol/2e8e2f5e22b03bfe4f22fbe30dd9c978 to your computer and use it in GitHub Desktop.
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
#!/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