diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2019-01-02 21:45:46 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2019-01-02 21:49:03 +1300 |
commit | b1cb59184d3e35a961d0139ae657a330ad9b1a13 (patch) | |
tree | a087b050acb2412b97d8dc2372cbae03d6fae8b8 | |
parent | Don't edit message headers using Emacs (diff) | |
download | dotfiles-b1cb59184d3e35a961d0139ae657a330ad9b1a13.tar.gz dotfiles-b1cb59184d3e35a961d0139ae657a330ad9b1a13.zip |
Add emacsclient logic to $VISUAL set
-rw-r--r-- | sh/profile.d/visual.sh | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/sh/profile.d/visual.sh b/sh/profile.d/visual.sh index 94aee963..359bf13a 100644 --- a/sh/profile.d/visual.sh +++ b/sh/profile.d/visual.sh @@ -1,9 +1,25 @@ -# If emacs is installed, and ~/.emacs exists, use emacs as the visual editor; -# otherwise, use the system's vi +# 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 - VISUAL=emacs + [ -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 |