[bin] Let `em` handle existing tmux sessions more gracefully

This commit is contained in:
Sebastian Schulze 2023-05-05 21:45:26 +02:00
parent 3d277673fd
commit c4efc214f8
No known key found for this signature in database
GPG Key ID: F6BA63C6A7D3044E
1 changed files with 9 additions and 1 deletions

View File

@ -3,9 +3,17 @@ PARENT_COMMAND=$(ps -o comm= $PPID)
TTY=""
export TTY
export TERM=xterm-24bit
declare name
raw_name=$(basename $(realpath $(pwd)/../))/$(basename $PWD)
name="${raw_name//./_}"
if [ "${PARENT_COMMAND}" == "$(basename "$SHELL")" ] || [ "${PARENT_COMMAND}" == "tmux: server" ]; then
exec emacsclient -s comacs --create-frame --tty "$@"
if [[ $(tmux display-message -p '#S' | grep -E "^\w+/\w+$") == "${name}" ]] && [[ -z ${1} ]]; then
echo "Detected tmux project session. (Re)-attaching";
exec emacsclient -s comacs --create-frame --tty -e "(bascht/switch-to-or-load-workspace \"${name}\" \"${PWD}\")"
else
exec emacsclient -s comacs --create-frame --tty "$@"
fi;
else
exec emacsclient --create-frame "$@"
fi;