This is a simple Zsh script designed to help developers who want to use AI services (like ChatGPT) to convert their code into multiple programming languages. The script’s goal is to streamline the process of adding a structured prompt to the clipboard for easier AI interaction.
- Automatically adds a customizable conversion prompt to existing code in the clipboard
- Supports multiple programming languages (e.g., Ruby, TypeScript, JavaScript, Java, Python)
- Uses
pbpaste
andpbcopy
for clipboard management - Designed for macOS, with an option for cross-platform extension
- Copy the code you want converted into other languages to your clipboard.
- Download the script and save it to a convenient location (e.g.,
~/scripts/prepend_prompt
). - Make it executable:
chmod u+x ~/scripts/prepend_prompt
- Call the script anytime you need to prepare code for conversion:
~/scripts/prepend_prompt
Automatically load the script into your shell environment by adding this to your ~/.zshrc
:
# custom executables:
path=("$HOME/scripts")
And then run source ~/.zshrc
.
Once the script runs, the following example prompt is added to the clipboard:
Please show me the original code for comparison, but do not convert it into
the language it's already written in. Detect the language and skip converting
it into the same language. Then convert the code into the following languages:
Ruby, TypeScript, JavaScript, Java, Python.
Please provide a detailed explanation of each part of the original code.
What does each operator and method in this code do?
Finally, provide a detailed summary of what the original code does.
<your clipboard code here>
- This script is a convenient way to interact with AI for learning and code conversion. However, keep in mind that AI responses should complement your own understanding, especially when it comes to syntax and best practices in different languages.
- By default, the script supports a set of languages, but it can easily be modified to include others. Additionally, it uses macOS clipboard utilities (
pbpaste
/pbcopy
), which can be replaced with Linux alternatives likexclip
for cross-platform usage.