aboutsummaryrefslogtreecommitdiff
path: root/sh/profile.d/visual.sh
blob: 359bf13a9d44909dd78297e793e020e1f92225f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# If an Emacs is installed, and ~/.emacs exists, use emacs as the visual
# editor; otherwise, use the system's vi
if command -v emacs >/dev/null 2>&1 &&
        [ -f "$HOME"/.emacs ] ; then

    # Use or start a GNU Emacs client, if possible
    if command -v pgrep >/dev/null 2>&1 &&
            pgrep --exact --full --euid="$USER" \
                'emacs --daemon' >/dev/null ||
            emacs --daemon >/dev/null ; then
        VISUAL=emacsclient

    # If no GNU Emacs daemon is available, just create a new instance every
    # time
    else
        VISUAL=emacs
    fi

# If an Emacs isn't installed, just use good old vi
else
    VISUAL=vi
fi

# Export final editor decision
export VISUAL