Your favorite Shell GPT commands #53
Replies: 9 comments 7 replies
-
I really like using it to generate mermaid.js diagrams of arbitrary code files:
Response: classDiagram
class OpenAIClient {
-api_key: str
-api_host: str
-cache: Cache
-chat_cache: ChatCache
+__init__(api_host: str, api_key: str): None
-_request(messages: List, model: str, temperature: float, top_probability: float): Dict
+get_completion(messages: List[str], model: str, temperature: float, top_probability: float, caching: bool): str
}
class Cache {
<<class>>
}
class ChatCache {
<<class>>
}
OpenAIClient --> Cache
OpenAIClient --> ChatCache
|
Beta Was this translation helpful? Give feedback.
-
With some added context I have been generating satellite imagery searches with sgpt successfully. In a way I am happy that even GPT4 cannot do this reliably so I have this side project to work on. 😄
|
Beta Was this translation helpful? Give feedback.
-
I've wrapped most things up into shell functions or aliases in my Call
Call
Generate code with less.... Well, you've probably figured out the pattern by now :)
A slightly different approach to what @TheR1D already mentioned with voice output (only Mac, sorry), this will vocalise and print to the screen.
Ok so here's something a little bit different. Basically piping in the output of a directory listing and getting some guesses as to the file contents
Some sample output from the above:
Lastly some interactive chat tools. ~~Personally, I only want a single, throwaway session, so I use the
I've updated this comment to incorporate suggestions/feedback from TheR1D |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
a rather verbose way to save all your transactions: function gpt() {
if [ -z "$2" ]; then
echo "no session provided"
local filename="$(date +"%Y-%m-%d")-sgpt.md"
else
local filename="$(date +"%Y-%m-%d")-$1-sgpt.md"
fi
local filedir="$HOME/sgpt"
local filepath="$filedir/$filename"
echo $filepath
if [[ "$1" == "open" ]]; then
echo "$1"
subl "$filedir"
return 0
fi
if [ -e "$filepath" ]; then
echo "$filepath already exists"
else
touch "$filepath"
echo "$filepath created"
fi
if [ -z "$2" ]; then
echo '## Prompt\n\n```bash\nsgpt \"$1\"\n```\n\n## Response\n' >> "$filepath"
sgpt "$1" | tee -a "$filepath"
else
echo '## Prompt\n\n```bash\nsgpt \"$2\"\n```\n\n## Response\n' >> "$filepath"
sgpt --chat "$1" "$2" | tee -a "$filepath"
fi
} as opposed to... #235 (comment) example usage gpt test-session "$(cat gpt-prompt-file.txt)" |
Beta Was this translation helpful? Give feedback.
-
I used this in my shell theme (zsh) to generate an emoji instead of the typical ai_emoji() {
command sgpt --model=gpt-3.5-turbo --cache \
"Return an emoji that could accompany this path in a shell prompt: ${PWD} and don't include any other text. If you can't think of one, instead return a symbol that would fit. Your response will be used as is in the shell prompt so provide no other output than just one symbol." \
| sed 's/^[[:space:]]*//;s/[[:space:]]*$//'
} Here's some examples:
|
Beta Was this translation helpful? Give feedback.
-
Generate code and watch it live in vscodium aicode() {
# Check if input is available from the pipe
if [ -t 0 ]; then
# If no input from pipe, pass only the prompt to the AI
sgpt --code "$@" | codium -
else
# If input is received from pipe, concatenate it with the provided prompt
cat - | sgpt --code "$@" | codium -
fi
} |
Beta Was this translation helpful? Give feedback.
-
Markdown and code highlighting and copy output to clipboard. |
Beta Was this translation helpful? Give feedback.
-
I have found this meeting minutes role to be pretty useful. #.config/shell_gpt/roles/min.json
For basic usage, you can just cat a transcript to it like this Using Wayland clipboard tools, I often just copy into the clipboard the file from my browser and run this |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There are many use cases for Shell GPT, such as generating shell commands, code, and more. Let's share our favorite commands in this discussion. I'll start with mine:
1. Say
It's really cool to use Shell GPT with the macOS default say command, which will read out the generated text for you. This is especially useful for large outputs:
say "$(sgpt 'Explain GitHub workflows')"
2. Conversions
I really like to use Shell GPT for all kinds of conversions:
3. Summarization and analyzing
Since GPT-3+ models can summarize and analyze text, we can use them to explain errors, code, and more. In this first example, we're calling a Python script that does a zero division (2 / 0), redirecting stderr to stdout, and passing it to sgpt:
In this second example, I'm passing the source code of the
sgpt
app module and asking for an explanation:Here are a few other use cases:
Beta Was this translation helpful? Give feedback.
All reactions