]> arthur.barton.de Git - ax-zsh.git/blobdiff - plugins/editor_select/editor_select.zprofile
editor_select: Validate an already set $EDITOR
[ax-zsh.git] / plugins / editor_select / editor_select.zprofile
index 08a0cf0581b5e751b41ae30b01f9e9d4b076076f..e55cf33c881d2ee7e9fc2764f7101937d3a3e8ed 100644 (file)
@@ -1,23 +1,38 @@
 # AX-ZSH: Alex' Modular ZSH Configuration
 # editor_select.zprofile: Setup $EDITOR for the "best" available editor
 
+if [[ -n "$EDITOR" && ! -x "$EDITOR" && -z "$commands[$EDITOR]" ]]; then
+       # Oops, current $EDITOR seems to be invalid! Start over!
+       unset EDITOR
+fi
+
 if [[ -z "$EDITOR" ]]; then
-       for editor in atom mate subl vim nano joe vi; do
-               if [ -n "$commands[$editor]" ]; then
+       # Auto-detect a "good" editor ...
+       if [[ -n "$DISPLAY" ]]; then
+               # X11 available, consider X11-based editors, too!
+               x11_editors="gvim"
+       fi
+
+       for editor (
+               code atom mate subl mvim
+               $x11_editors
+               vim nano joe vi
+       ); do
+               if [[ -n "$commands[$editor]" ]]; then
                        EDITOR="$commands[$editor]"
                        break
                fi
        done
-       unset editor
+       unset editor x11_editors
 fi
 
-case "$(basename "$EDITOR")" in
-       "atom"|"mate"|"subl")
+case "$EDITOR:t" in
+       "code"|"atom"|"mate"|"subl")
                EDITOR="$EDITOR --wait"
                ;;
+       "mvim"|"gvim")
+               EDITOR="$EDITOR --nofork"
+               ;;
 esac
 
-if [ -n "$EDITOR" ]; then
-       export EDITOR
-       alias zshenv="$EDITOR ~/.zshenv"
-fi
+[[ -n "$EDITOR" ]] && export EDITOR