]> arthur.barton.de Git - ax-zsh.git/blob - plugins/editor_select/editor_select.zprofile
editor_select: Check the user preferences first!
[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         # Check user preferences first!
11         if [[ -r ~/.selected_editor ]]; then
12                 . ~/.selected_editor
13                 if [[ -x "$SELECTED_EDITOR" || -n "$commands[$SELECTED_EDITOR]" ]]; then
14                         EDITOR="$SELECTED_EDITOR"
15                 fi
16                 unset SELECTED_EDITOR
17         fi
18 fi
19
20 if [[ -z "$EDITOR" ]]; then
21         # Auto-detect a "good" editor ...
22         if [[ -n "$DISPLAY" ]]; then
23                 # X11 available, consider X11-based editors, too!
24                 x11_editors="gvim"
25         fi
26
27         for editor (
28                 sensible-editor
29                 code atom mate subl mvim
30                 $x11_editors
31                 vim nano joe vi
32         ); do
33                 if [[ -n "$commands[$editor]" ]]; then
34                         EDITOR="$commands[$editor]"
35                         break
36                 fi
37         done
38         unset editor x11_editors
39 fi
40
41 case "$EDITOR:t" in
42         "code"|"atom"|"mate"|"subl")
43                 EDITOR="$EDITOR --wait"
44                 ;;
45         "mvim"|"gvim")
46                 EDITOR="$EDITOR --nofork"
47                 ;;
48 esac
49
50 [[ -n "$EDITOR" ]] && export EDITOR