From d12f5f38e1e9a5df142697faff6ad4245917a90c Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 15 May 2021 22:49:52 +0100 Subject: [PATCH] chore(emacs): improve shell setup --- bin/emacsclient-wrapper | 20 ++++++++++++++++---- zsh/emacs.zsh | 27 +++++++++++---------------- zshenv | 14 ++++++++++++++ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/bin/emacsclient-wrapper b/bin/emacsclient-wrapper index 1b35a0e..551807a 100755 --- a/bin/emacsclient-wrapper +++ b/bin/emacsclient-wrapper @@ -4,11 +4,23 @@ EMACSCLIENT="emacsclient" ALTERNATE_EDITOR="nano" +if [ -d "/opt/emacs/bin" ] && [[ ":${PATH}:" != *":/opt/emacs/bin:"* ]]; then + export PATH="/opt/emacs/bin:$PATH" +fi + # Set to binary bundled in Emacs.app if it exists -if [ -f "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" ]; then - EMACSCLIENT="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" +if [[ "$OSTYPE" == "darwin"* ]]; then + if [ -f "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" ]; then + EMACSCLIENT="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" + fi +fi + +if command -v toe &> /dev/null && toe | grep '24bit' &> /dev/null; then + FULL_COLOR_TERM="$(toe | grep '24bit' | head -n1 | awk '{ print $1 }')" + if [ -n "$FULL_COLOR_TERM" ]; then + export TERM="$FULL_COLOR_TERM" + fi fi # Execute emacsclient -exec env TERM=screen-24bit \ - $EMACSCLIENT --alternate-editor=$ALTERNATE_EDITOR "$@" +exec $EMACSCLIENT --alternate-editor=$ALTERNATE_EDITOR "$@" diff --git a/zsh/emacs.zsh b/zsh/emacs.zsh index 815353d..b6b9f9c 100644 --- a/zsh/emacs.zsh +++ b/zsh/emacs.zsh @@ -2,23 +2,18 @@ # Emacs # -# macOS systems -if [[ "$OSTYPE" == "darwin"* ]]; then - if [ -f "/Applications/Emacs.app/Contents/MacOS/Emacs" ]; then - export EMACS="/Applications/Emacs.app/Contents/MacOS/Emacs" - alias emacsgui="env TERM=screen-24bit $EMACS" - alias emacs="env TERM=screen-24bit $EMACS -nw" - fi +# Depends on EMACS and EMACSCLIENT environment variables set in ~/.zshenv - if [ -f "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" ]; then - alias emacsclient="env TERM=screen-24bit /Applications/Emacs.app/Contents/MacOS/bin/emacsclient" - fi -fi - -# Linux systems -if [[ "$OSTYPE" == "linux"* ]]; then - alias emacs="env TERM=screen-24bit emacs -nw" - alias emacsclient="env TERM=screen-24bit emacsclient" +# Enforce 24-bit color mode if available +if command-exists toe && toe | grep '24bit' &> /dev/null; then + FULL_COLOR_TERM="$(toe | grep '24bit' | head -n1 | awk '{ print $1 }')" + alias emacsgui="env TERM=$FULL_COLOR_TERM $EMACS" + alias emacs="env TERM=$FULL_COLOR_TERM $EMACS -nw" + alias emacsclient="env TERM=$FULL_COLOR_TERM $EMACSCLIENT" +else + alias emacsgui="$EMACS" + alias emacs="$EMACS -nw" + alias emacsclient="$EMACSCLIENT" fi # add doom-emacs' bin directory to path if it exists diff --git a/zshenv b/zshenv index c3766b1..bb12967 100644 --- a/zshenv +++ b/zshenv @@ -146,6 +146,20 @@ export KUBECONFIG="$HOME/.kube/config:.kube/config" # Use custom emacs install if available path_prepend "/opt/emacs/bin" +# Set Emacs-related environment variables +export EMACS="emacs" +export EMACSCLIENT="emacsclient" + +# On macOS we want to use the Emacs.app application bundle +if [[ "$OSTYPE" == "darwin"* ]]; then + if [ -f "/Applications/Emacs.app/Contents/MacOS/Emacs" ]; then + export EMACS="/Applications/Emacs.app/Contents/MacOS/Emacs" + fi + if [ -f "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" ]; then + export EMACSCLIENT="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" + fi +fi + # Use custom tmux install if available path_prepend "/opt/tmux/bin"