Skip to content

Instantly share code, notes, and snippets.

@kunalb
Created February 8, 2026 22:01
Show Gist options
  • Select an option

  • Save kunalb/3cb853bc4af2eb4a3cf370356f2f97ad to your computer and use it in GitHub Desktop.

Select an option

Save kunalb/3cb853bc4af2eb4a3cf370356f2f97ad to your computer and use it in GitHub Desktop.
Wrapper scripts & functions to launch emacs with a custom directory
#!/bin/bash
INIT_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aiemacs"
SOCKET_DIR="${XDG_RUNTIME_DIR:-/tmp}/emacs-aiemacs"
EMACS_SOCKET_NAME="$SOCKET_DIR/server"
export EMACS_SOCKET_NAME
# Ensure socket directory exists with secure permissions
mkdir -p "$SOCKET_DIR" && chmod 700 "$SOCKET_DIR"
# Ensure init directory has secure permissions
chmod 700 "$INIT_DIR" 2>/dev/null
# Start server if not running
if ! emacsclient -s "$EMACS_SOCKET_NAME" -e nil &>/dev/null; then
emacs --init-directory="$INIT_DIR" --daemon="$EMACS_SOCKET_NAME"
fi
exec emacsclient -t -s "$EMACS_SOCKET_NAME" "$@"
function aen {
emacs -nw --init-directory=$XDG_CONFIG_HOME/aiemacs "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment