Skip to content

Instantly share code, notes, and snippets.

@aeghn
Last active August 16, 2020 11:15
Show Gist options
  • Save aeghn/e50187879af69a11f410a43de2047ed4 to your computer and use it in GitHub Desktop.
Save aeghn/e50187879af69a11f410a43de2047ed4 to your computer and use it in GitHub Desktop.
#!/bin/bash
DEFAULT_SOCKET=default
CHINBOX_SOCKET=chinbox
#export LIBRARY_PATH="$HOME/.local/include/"
_emacs="$HOME/.local/bin/emacs"
_emacsclient="$HOME/.local/bin/emacsclient"
#_emacs="/usr/local/bin/emacs"
#_emacsclient="/usr/local/bin/emacsclient"
#_emacs="emacs"
#_emacsclient="emacsclient"
# Set true to disable the external input method.
DEIM=true
_start_default() {
local default_emacsclient _dunstify
default_emacsclient="$_emacsclient"
_dunstify="dunstify -i $HOME/.scripts/res/icons/emacs.svg -r 2603 Emacs"
if $default_emacsclient -e nil > /dev/null ;then
echo "Emacs daemon is running"
else
$_dunstify "Daemon is booting"
$_emacs --daemon 2>&1
return_code=$?
echo "Emacs return code: $return_code"
[ $return_code -ne 0 ] && $_dunstify -t 60000 "Emacs return code: $return_code"
fi
$default_emacsclient -c &
i3-msg "workspace --no-auto-back-and-forth 1"
}
_start_chinbox() {
todo=$HOME/orgs/chinbox/inbox.org
chinbox_emacsclient="$_emacsclient --socket-name=$CHINBOX_SOCKET"
if ! _i3msg Chin_box; then
if ! $chinbox_emacsclient -e nil; then
_EMACS_LOAD_MODE_="$CHINBOX_SOCKET" $_emacs --daemon="$CHINBOX_SOCKET"
dunstify -i "$HOME/.scripts/res/icons/chinbox.png" -t 3000 "Chinbox" "Daemon is booting"
fi
$chinbox_emacsclient -c -F '((name . "Chin_box") (transient . t))' -e "(find-file \"$todo\")" &
while ! _i3msg Chin_box; do
sleep 0.10
done
fi
}
_i3msg() {
i3-msg "[title=^$@$] scratchpad show"
return $?
}
_process() {
local daemons pids
local IFS=$'\n'
daemons=($(pgrep -a emacs | grep "\-\-daemon"))
pids=($(printf "%s\n" "${daemons[@]}"|awk -F" " '{print $1}'))
for i in ${!daemons[@]}; do
printf "%s\n" "$i ${daemons[$i]}"
done
local IFS=' '
read -a marks -p "Select process you want to kill: "
for i in ${marks[@]}; do
kill ${pids[$i]}
done
}
if $DEIM ; then
export XMODIFIERS=@im=
fi
if [ $# -eq 0 ]; then
_start_default
elif [ "$1" = c ]; then
_start_chinbox
elif [ "$1" = p ]; then
_process
else
cat <<EOF
! Unsupported args.
aemacs
[void] -- start default emacs
c -- start chinbox
p -- showprocess
EOF
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment