-
-
Save ntessore/9a950687da667cf6955c to your computer and use it in GitHub Desktop.
edit: wrapper script to launch editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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