Skip to content

Instantly share code, notes, and snippets.

@ntessore
Last active March 9, 2016 11:29
Show Gist options
  • Save ntessore/9a950687da667cf6955c to your computer and use it in GitHub Desktop.
Save ntessore/9a950687da667cf6955c to your computer and use it in GitHub Desktop.
edit: wrapper script to launch editor
#!/bin/bash
##############################################################################
# One command to edit files from the command line. Helps your muscle memory. #
# #
# Do you instinctively write `mate` or `atom` to edit files, only to get #
# told `command not found` because you forgot you are in a SSH session? #
# The `edit` script is a simple wrapper that launches the command specified #
# through the `$EDITOR`, `$VISUAL` or `$EDIT_EDITOR` environment variable. #
# In this way, you will always use the same command to start editing files. #
# #
# To install: #
# #
# $ curl -LO https://git.io/edit; chmod +x edit #
# #
##############################################################################
# gather editor command
if [ -n "$EDITOR" ]; then edit="$EDITOR"; fi
if [ -n "$VISUAL" ]; then edit="$VISUAL"; fi
if [ -n "$EDIT_EDITOR" ]; then edit="$EDIT_EDITOR"; fi
# make sure editor is set
if [ -z "$edit" ]; then
echo "edit: no editor (set EDITOR, VISUAL or EDIT_EDITOR)" 1>&2
exit 1
fi
# launch editor and pass all arguments
$edit "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment