justin․searls․co

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_party
  • edit -e vim rails/rails – will change to the ~/code/rails/rails directory and run vim
  • edit testdouble/mo[TAB] – will auto-complete to edit testdouble/mocktail
  • edit 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 to cursor (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:

  1. Add the edit executable to a directory on your PATH
  2. Make sure edit is executable with chmod +x edit
  3. Download the edit.bash bash completions and put them somewhere
  4. In .profile or .bashrc or whatever, run source 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):

Make it executable:

chmod +x ~/bin/edit

2. Add bash completion

Download the completion script:

Source it in your shell profile. Here's how I do it in my .profile:

# 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:

  1. Absolute paths - Used as-is
  2. Current directory - ./path or .
  3. Org/repo patterns - org/repo format:
    • Check if ~/code/org/repo exists
    • If not, clone git@github.com:org/repo.git
  4. Bare repo names - repo_name format:
    • 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

Got a taste for hot, fresh takes?

Then you're in luck, because you'll pay $0 for my 2¢ when you subscribe to my work, whether via RSS or your favorite social network.

I also have a monthly newsletter where I write high-tempo, thought-provoking essays about life, in case that's more your speed:

And if you'd rather give your eyes a rest and your ears a workout, might I suggest my long-form solo podcast, Breaking Change? Odd are, you haven't heard anything quite like it.