A handy script for launching editors
Today, I want to share with you a handy edit script I use to launch my editor countless times each day. It can:
edit posse_party– will launch my editor with project~/code/searls/posse_partyedit -e vim rails/rails– will change to the~/code/rails/railsdirectory and runvimedit testdouble/mo[TAB]– will auto-complete toedit testdouble/mocktailedit emoruby– will, if not found locally, clone and open searls/emoruby
This script relies on following the convention of organizing working copies of projects in a GitHub <org>/<repo> format (under ~/code by default). I can override this and a few other things with environment variables:
CODE_DIR- defaults to"$HOME/code"DEFAULT_ORG- defaults to"searls"DEFAULT_EDITOR- defaults tocursor(for the moment)
I've been organizing my code like this for 15 years, but over the last year I've found myself bouncing between various AI tools so often that I finally bit the bullet to write a custom meta-launcher.
If you want something like this, you can do it yourself:
- Add the edit executable to a directory on your
PATH - Make sure
editis executable withchmod +x edit - Download the edit.bash bash completions and put them somewhere
- In .profile or
.bashrcor whatever, runsource path/to/edit.bash
The rest of this post is basically a longer-form documentation of the script that you're welcome to peruse in lieu of a proper README.
Setup
1. Install the script
Download the main script to your ~/bin/ directory (or someplace on your PATH):
- edit script - The main script
Make it executable:
chmod +x ~/bin/edit
2. Add bash completion
Download the completion script:
- edit.bash - Tab completion logic
Source it in your shell profile. Here's how I do it in my .profile:
- .profile example - Loading completions
# Add to ~/.bashrc, ~/.bash_profile, or ~/.profile
source ~/path/to/bash-completions/edit.bash
3. Configure (optional)
Set these environment variables to customize behavior:
export CODE_DIR="$HOME/code" # Where your repos live (default: ~/code)
export DEFAULT_ORG="searls" # Your primary GitHub org (default: searls)
export DEFAULT_EDITOR="cursor" # Your preferred editor (default: cursor)
Usage Examples
Basic repository access:
edit posse_party # ~/code/searls/posse_party
edit testdouble/mocktail # ~/code/testdouble/mocktail
Editor selection:
edit -e vim posse_party # Open with vim
edit -e code project_name # Open with VS Code
edit -e claude . # Open current dir with Claude
Tab completion magic:
edit pos[TAB] # Completes to: posse_party
edit searls/pos[TAB] # Completes to: searls/posse_party
edit testd[TAB] # Completes to: testdouble/
edit --editor [TAB] # Shows: vim code code-insiders cursor claude
Automatic cloning:
edit new_repo # Will clone searls/new_repo if it doesn't exist locally
edit microsoft/vscode # Will clone microsoft/vscode to ~/code/microsoft/vscode
Supported Editors
- vim - Changes to directory and runs
vim . - code/code-insiders - Runs
code{-insiders} <path> - cursor - Runs
cursor <path> - claude - Changes to directory and runs
claude
Path Resolution Logic
The script tries these locations in order:
- Absolute paths - Used as-is
- Current directory -
./pathor. - Org/repo patterns -
org/repoformat:- Check if
~/code/org/repoexists - If not, clone
git@github.com:org/repo.git
- Check if
- Bare repo names -
repo_nameformat:- Check current directory
- Check
~/code/repo_name - Check
~/code/$DEFAULT_ORG/repo_name - If not found, clone
git@github.com:$DEFAULT_ORG/repo_name.git
Features
- ✅ Smart path resolution with multiple fallback strategies
- ✅ Automatic GitHub cloning when repositories don't exist locally
- ✅ Multi-editor support with per-editor optimizations
- ✅ Intelligent tab completion that matches the script's path logic
- ✅ Environment variable configuration for customization
- ✅ Error handling with helpful messages for troubleshooting