# Small script to toggle DO-NOT-DISTURB mode # and make it integrate well with other applications {pkgs, ...}: pkgs.writeShellApplication { name = "do-not-disturb"; runtimeInputs = with pkgs; [ coreutils mako systemd ]; text = '' MAKO_DEFAULT_MODE=default MAKO_SILENT_MODE=do-not-disturb # Sanity checks if [ -z "''${1+x}" ]; then print_help fi if [ -z "''${XDG_RUNTIME_DIR+x}" ]; then printf "XDG_RUNTIME_DIR undefined! Cannot connect to mako!\n" exit 1 fi state="$XDG_RUNTIME_DIR/do-not-disturb" # Print usage information function print_help() { printf "Usage:\n" printf " %s [ toggle | is-on | is-off | get-file ]\n" "$0" exit 1 } # Toggle the mode function toggle() { if [ -f "$state" ]; then rm "$state" else touch "$state" fi } # Update mako's mode to this scripts mode function update-mako() { if [ -f "$state" ]; then makoctl set-mode $MAKO_SILENT_MODE else makoctl set-mode $MAKO_DEFAULT_MODE fi } action=$1 if [ "$action" = "toggle" ]; then toggle update-mako elif [ "$action" = "is-on" ]; then [ -f "$state" ] elif [ "$action" = "is-off" ]; then [ ! -f "$state" ] elif [ "$action" = "get-file" ]; then printf "%s" "$state" else print_help fi ''; }