• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (deprecated)
You are here: Home / Dev Tips / Git Editor Roulette

Git Editor Roulette

Last updated on July 4, 2025 by Sal Ferrarello

A question came up about setting the Git editor to a bash function, which I could not figure out. I was, however, able to set the Git editor to a bash script. As a proof of concept, here is a bash script to randomly choose an editor (nano or vim) when using Git.

I saved this file as ~/my-random-git-editor-script

#!/bin/bash

if (( RANDOM % 2 )); then
    editor="nano"
else
    editor="vim"
fi

exec "$editor" "$@"

and made it executable by running

chmod +x ~/my-random-git-editor-script

and finally I updated my Git config to use the script by running

git config --global core.editor "~/my-random-git-editor-script"
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP and JavaScript developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a principal engineer.

Filed Under: Computing, Dev Tips, Solution Tagged With: command line, Git, git log

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2026 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in