From: Alexander Barton Date: Fri, 27 Mar 2015 15:03:03 +0000 (+0100) Subject: Add "editor_select" plugin: Auto-detect usable editor X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=OhMyZshExtensions.git;a=commitdiff_plain;h=f888b81bacf82fe3b2919c2b4543e9130fdd8a2d Add "editor_select" plugin: Auto-detect usable editor --- diff --git a/plugins/editor_select/editor_select.plugin.zsh b/plugins/editor_select/editor_select.plugin.zsh new file mode 100644 index 0000000..423b2dc --- /dev/null +++ b/plugins/editor_select/editor_select.plugin.zsh @@ -0,0 +1,24 @@ +# editor-select.plugin.zsh +# 2015-03-27, alex@barton.de + +if [ -z "$EDITOR" ]; then + # Check "mate" + EDITOR=`which mate 2>/dev/null` + if [ $? -eq 0 ]; then + EDITOR="$EDITOR --wait" + else + # Check "subl" + EDITOR=`which subl 2>/dev/null` + if [ $? -eq 0 ]; then + EDITOR="$EDITOR --wait" + else + # Check "vim" + EDITOR=`which vim 2>/dev/null` + if [ $? -ne 0 ]; then + # Check "vi" + EDITOR=`which vi 2>/dev/null` + fi + fi + fi +fi +[ -n "$EDITOR" ] && export EDITOR