#!/bin/bash set -o errexit set -o nounset set -o pipefail shopt -s globstar nullglob function show_help () { cat >&2 <&2 "$(basename "$0") $(date +'%T %Z')" "$@" exit 1 elif ((NVOL <= VERBOSITY)); then echo "$(basename "$0") $(date +'%T %Z')" "$@" fi return 0 } #------------------------------------------------------------------------------ # Express the VERBOSITY as an option string. function vopt () { local str="" if ((0 < VERBOSITY)); then str="-v" fi for ((i = 1; i < VERBOSITY; i++)); do str="${str}v" done echo "$str" return 0 } #------------------------------------------------------------------------------ squawk 1 "$(date --iso) started." if [[ -n "${INSIDE_EMACS:-}" ]]; then squawk 1 "I'm inside emacs..." emacsclient "$@" else squawk 1 "Not inside emacs..." # Attempt to clean up the possible messes that emacs makes. if ! pgrep --uid "$LOGNAME" --full 'emacs --daemon' >/dev/null then squawk 1 "No daemon, clearing lock..." rm -f ~/.emacs.d/.emacs.desktop.lock elif ! [[ -S /run/user/$UID/emacs/server ]] then squawk 1 "Killing daemon that lost its socket..." pkill --signal SIGKILL --uid "$LOGNAME" --full 'emacs --daemon' squawk 1 "Clearing lock..." rm -f ~/.emacs.d/.emacs.desktop.lock fi squawk 1 "daemon state should be good, so starting client..." exec emacsclient --tty --alternate-editor="" "$@" fi squawk 1 "done." exit 0