emacs-config/bin/emacs_ctl

73 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
state=/tmp/emacs-use-dark-mode
start_daemon () {
emacs --fg-daemon > /dev/null 2>&1
}
stop_daemon () {
emacsclient --eval "(kill-emacs)" 2> /dev/null
}
kill_daemon () {
killall emacsclient 2> /dev/null
killall emacs 2> /dev/null
}
restart_daemon () {
stop_daemon
start_daemon
}
hard_restart_daemon () {
kill_daemon
start_daemon
}
set_light () {
echo 0 > "$state"
}
set_dark () {
echo 1 > "$state"
}
if [[ -z "$1" ]]; then
echo "Need a command to perform"
exit 1
elif [[ "$1" == "start" ]]; then
start_daemon &
elif [[ "$1" == "stop" ]]; then
stop_daemon
elif [[ "$1" == "kill" ]]; then
kill_daemon
elif [[ "$1" == "theme" ]]; then
if [[ "$2" == "toggle" ]]; then
# if no state file assume light theme
if [[ ! -f "$state" ]]; then
set_light
elif [[ "$(cat $state)" == 0 ]]; then
set_dark
else
set_light
fi
elif [[ "$2" == "light" ]]; then
set_light
elif [[ "$2" == "dark" ]]; then
set_dark
else
echo 'Invlalid theme command'
exit 1
fi
if [ "$3" == "restart" ]; then
restart_daemon &
elif [ "$3" == "hard_restart" ]; then
hard_restart_daemon &
fi
else
echo 'Invalid command'
exit 1
fi