in Projects, Programming, Technology

Magic Shell

I’ve been wanting Copilot-like auto-complete functionality for the command prompt. Github Copilot has made me 3-5x more productive when writing code. So I decided to write my own “Magic Shell” script, and open-source it here. It’s not an exaggeration to say this has made me 10x more productive at the command line since I no longer have to Google basic commands.

A basic version is also available via Keep reading for the advanced version with short and long-term memory to make the experience more conversational.

AI-enhanced shell prompt demo video

Installation Instructions

This was written and tested in Mac Z shell (zsh) using Python 3.10.

  1. Get an API KEY from OpenAI, and set it in your environment.
$ export OPENAI_API_KEY={your api key} 
  1. Other than Python, the only dependency is the openai python library.
$ pip install openai 

2. Put these 2 files in a folder (like ~/Projects/magicshell)

a. prompt.txt (preserve the line break at the end of the file)


Now we’re ready to go (from inside that folder).

$ python what time is it 
Note: Don't include quotes or punctuation in your command.

4. Let’s create an alias for that to make it easier. I added this to my ~/.zshrc file

export OPENAI_API_KEY={your api key} 
alias please="python ~/Projects/magicshell/" 

So now can just write please and omit the python part.

$ please delete remote git branch called temp 

What is Z shell (Zsh)? The Mac Z shell (Zsh) is a powerful command-line interpreter for macOS that offers advanced features and customization options for shell scripting and interactive use. The .zshrc file is a configuration file used by the Zsh shell on macOS that allows users to customize their shell environment, set aliases, define functions, and configure various options for their terminal session.


The script will create two files: shortterm_memory.txt and longterm_memory.txt in the folder where you placed Short-term memory is a text file with the most recent commands. So you should be able to type:

$ please create a folder named myproject 
$ please place a text file called test.txt in that folder 

Note that if you don’t run a suggested command, it won’t be saved to short-term memory.

Long-term memory is a text file that constantly grows. So you can type

$ please remember my name is Adam 

And then tomorrow, write please add my name to the file.

Features I want to add

todo: Add an explain command

todo: Add a search (the web command)

todo: bootstrap artificial general intelligence behind this script

todo: add “forget” to wipe memory

Any other ideas, please leave a comment below!

Write a Comment


  1. Sinceramente eu adorei o seu artigo muito bom mesmo o seu projeto me parece algo muito valioso que dará muito certo com certeza.

    Honestly I loved your article very good even your project seems to me something very valuable that will work very well for sure.