You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
61 lines
2.0 KiB
#!/bin/zsh |
|
|
|
# Helper to fetch last return status |
|
function laststatus { return $? } |
|
|
|
emacs-session-name() { |
|
if [[ "$EMACS_FORCE_SESSION" != '' ]];then |
|
echo $EMACS_FORCE_SESSION |
|
elif [[ "$SSH_CONNECTION" != '' ]]; then |
|
echo ssh-server |
|
else |
|
echo "$(kde-current-activity-name)" |
|
fi |
|
} |
|
|
|
|
|
|
|
kde-current-activity () { |
|
qdbus6 org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.CurrentActivity |
|
} |
|
|
|
kde-current-activity-name () { |
|
qdbus6 org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.ActivityName `kde-current-activity` |
|
} |
|
|
|
# Check if server has been started and start it otherwise |
|
emacs-server-start () { |
|
if ! emacsclient -s "$(emacs-session-name)" -e '(version)' &> /dev/null; then |
|
autoload colors;colors |
|
echo Starting $fg_bold[magenta]emacs daemon$reset_color with session $fg[blue]$(emacs-session-name)$reset_color |
|
/usr/bin/emacs --daemon="$(emacs-session-name)" &>/dev/null; |
|
fi |
|
} |
|
|
|
# This ensures that the right server is started; |
|
# I guess it can be done with -a "" when calling emacsclient, but |
|
# eventually I want to start emacs servers when the activity changes, |
|
# so this would need to be done separately anyways. |
|
|
|
emacs-server-start |
|
|
|
if [[ "$SSH_CONNECTION" != '' ]]; then |
|
exec emacsclient -s ssh-server -t "$@" |
|
else |
|
|
|
# This ensures that a new frame is created if only the default (tty) |
|
# one is present. It also names the new frame, in case I decide to |
|
# create secondary frames (e.g. for the agenda). |
|
|
|
emacsclient -s "$(emacs-session-name)" -n -e "(if (> (length (frame-list)) 1) 't)" | grep t >/dev/null; |
|
if [ "$?" = "1" ]; then |
|
exec emacsclient -s "$(emacs-session-name)" -c --frame-parameters="(quote (name . \"ε on $(emacs-session-name)\"))" "$@" |
|
else |
|
exec emacsclient -s "$(emacs-session-name)" "$@" |
|
fi |
|
fi |
|
STATUS=$?; |
|
|
|
# This does not seem to be needed anymore |
|
#emacsclient -s "$(emacs-session-name)" -e '(recenter-top-bottom)' |
|
return $STATUS
|
|
|