As developers, we’re always on the lookout for tools that can enhance our productivity and make our lives easier. Well, say hello to Shell-GPT, a game-changing command-line productivity tool that harnesses the power of OpenAI’s ChatGPT (GPT-3.5) to supercharge your development process. With Shell-GPT, you can now generate shell commands, code snippets, comments, and documentation, all within the familiar confines of your terminal. No more need for cheat sheets or endless Google searches – this innovative tool brings accurate answers right to your fingertips.
Getting started with Shell-GPT is a breeze. Simply run the following command to install it:
pip install shell-gpt
To start using Shell-GPT, you’ll need an OpenAI API key. You can generate one from the OpenAI website. Once you have your API key, Shell-GPT will automatically use the $OPENAI_API_KEY
environment variable if it’s set, or it will prompt you to enter the key and store it in ~/.config/shell_gpt/.sgptrc
for future use.
Shell-GPT is a versatile tool with a wide range of use cases, making it an invaluable asset for developers. Let’s explore some of the scenarios where Shell-GPT can come to your rescue.
With Shell-GPT, you can use your terminal as a powerful search engine. Ask any question, and get accurate answers instantly:
sgpt "What is the capital of France?"
# -> The capital of France is Paris.
sgpt "How do I check my public IP address?"
# -> You can check your public IP address by running: `curl ifconfig.me`
sgpt "How many bytes are there in a kilobyte?"
# -> 1 kilobyte is equal to 1024 bytes.
Finding and executing shell commands has never been easier. Just use the --shell
option:
sgpt --shell "Create a new directory named 'project'"
# -> mkdir project
sgpt --shell "List all files in the current directory"
# -> ls
sgpt --shell "Remove a file named 'data.txt'"
# -> rm data.txt
And if you want to directly execute the received command, simply add the --execute
(or -se
) parameter:
sgpt --shell --execute "Install required Python packages"
# -> pip install numpy matplotlib pandas
# -> Execute shell command? [y/N]: y
# ...
Need to generate code snippets quickly? Shell-GPT has got you covered. Use the --code
parameter along with your query:
sgpt --code "Generate a random number between 1 and 10 in Python"
# -> import random
# -> random_number = random.randint(1, 10)
# -> print(random_number)
And since the output is valid Python code, you can easily redirect it to a file:
sgpt --code "Create a simple web server using Flask"
# -> from flask import Flask
# ->
# -> app = Flask(__name__)
# ->
# -> @app.route('/')
# -> def hello_world():
# -> return 'Hello, World!'
# ->
# -> if __name__ == '__main__':
# -> app.run()
# ->
# -> Save this code in a file named 'app.py' and run it using 'python app.py'
Want to have interactive sessions with ChatGPT to improve its suggestions iteratively? Shell-GPT makes it a breeze:
sgpt --chat language "Translate 'hello' to French"
# -> 'hello' in French is 'bonjour'.
sgpt --chat calculation "What is the square root of 144?"
# -> The square root of 144 is 12.
In conclusion, Shell-GPT brings the power of AI right into your development workflow. By delivering quick, accurate, and context-aware answers directly within your terminal, Shell-GPT revolutionizes the way you interact with the command line, boosting your efficiency and effectiveness.
Stay tuned for more exciting AI and No-Code content like this, and feel free to drop any questions you have in the comments below.
Thanks for reading! Happy coding with Shell-GPT!