ADD master control file

This commit is contained in:
Nathan Dwarshuis 2024-03-04 20:49:16 -05:00
parent 520477884b
commit b04ba759c9
1 changed files with 72 additions and 0 deletions

72
bin/emacs_ctl Executable file
View File

@ -0,0 +1,72 @@
#!/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