]> arthur.barton.de Git - ax-zsh.git/blob - plugins/editor_select/editor_select.zprofile
editor_select: Validate an already set $EDITOR
[ax-zsh.git] / plugins / editor_select / editor_select.zprofile
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # editor_select.zprofile: Setup $EDITOR for the "best" available editor
3
4 if [[ -n "$EDITOR" && ! -x "$EDITOR" && -z "$commands[$EDITOR]" ]]; then
5         # Oops, current $EDITOR seems to be invalid! Start over!
6         unset EDITOR
7 fi
8
9 if [[ -z "$EDITOR" ]]; then
10         # Auto-detect a "good" editor ...
11         if [[ -n "$DISPLAY" ]]; then
12                 # X11 available, consider X11-based editors, too!
13                 x11_editors="gvim"
14         fi
15
16         for editor (
17                 code atom mate subl mvim
18                 $x11_editors
19                 vim nano joe vi
20         ); do
21                 if [[ -n "$commands[$editor]" ]]; then
22                         EDITOR="$commands[$editor]"
23                         break
24                 fi
25         done
26         unset editor x11_editors
27 fi
28
29 case "$EDITOR:t" in
30         "code"|"atom"|"mate"|"subl")
31                 EDITOR="$EDITOR --wait"
32                 ;;
33         "mvim"|"gvim")
34                 EDITOR="$EDITOR --nofork"
35                 ;;
36 esac
37
38 [[ -n "$EDITOR" ]] && export EDITOR