#!/usr/bin/env nix-shell #!nix-shell -i bash -p bash -p s6 -p s6-rc # for default $PATH to take precedence over nix-shell PATH if invoked interactively, # otherwise we invoke a s6-rc which does not know where to find files. export PATH="/etc/profiles/per-user/$(whoami)/bin:/run/current-system/sw/bin:$PATH" action="$1" service="$2" log() { if [ -n "$SWAYNC_DEBUG" ]; then printf "%s\n" "$1" fi } checkActive() { # simulate a dry-run start. if no actions would be performed, then the service is up. # alternative is s6-svstat, but that doesn't support oneshots test -z "$(s6-rc -n 0 -b start "$service")" && echo true || echo false } startService() { log "startService: $service" s6-rc -b start "$service" } stopService() { log "stopService: $service" s6-rc -b stop "$service" } case "$action" in print) checkActive ;; toggle) case "$(checkActive)" in false) startService ;; true) stopService ;; esac ;; esac