-
-
Save anler/11137890 to your computer and use it in GitHub Desktop.
Edit command to launch Emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# To automatically start Emacs in daemon mode if there's no daemon already | |
# running, set: | |
# | |
# export ALTERNATE_EDITOR="" | |
# | |
# Automatically choose how to open Emacs: | |
# 1. If running in interactive terminal use the same terminal. | |
# 2. If there's a frame created, use that frame. | |
# 3. Otherwise create a new frame and use it. | |
# | |
if $(tty -s); then | |
# Launch Emacs in the terminal if running in interactive mode | |
emacsclient -t -a "$ALTERNATE_EDITOR" $1 | |
else | |
# When non-interactive. | |
# Detect if there is an Emacs frame already created. | |
if $(emacsclient -e "(frame-list)" | grep "<frame emacs@"); then | |
# If there's one, use it. | |
emacsclient -n -a "$ALTERNATE_EDITOR" $1 | |
else | |
# Otherwise create a new one. | |
emacsclient -c -n -a "$ALTERNATE_EDITOR" $1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment