Skip to content

Instantly share code, notes, and snippets.

@mrballcb
Last active September 1, 2022 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrballcb/1a3c6c293e26d7c44d082270de625599 to your computer and use it in GitHub Desktop.
Save mrballcb/1a3c6c293e26d7c44d082270de625599 to your computer and use it in GitHub Desktop.
Helper script for lungo on MacOS
Usage:
# Both of these will activate lungo for 10 hours
lungo 10 hours
lungo hours=10
# Both of these will toggle lungo off if it's on, or on indefinitely if it was off
lungo toggle
lungo
# This doesn't look like it should work to deactivate, but it does. Dunno why
lungo deactivate
# Scripting explanations from website:
https://sindresorhus.com/lungo#scripting
#!/usr/bin/env bash
set -euo pipefail
CLIARGS=${1-toggle}
if [[ $CLIARGS =~ (hours|minutes)= ]]; then
# Passed "hours=NN" (native) format
ARGS="activate?$CLIARGS"
elif [[ $CLIARGS =~ [[:digit:]]+ ]] && [[ $2 =~ hours|minutes ]]; then
# Passed "NN hours" format
ARGS="activate?$2=$1"
else
# Hope user passed in correct arg for lungo.
# Lungo ignores any arg it doesn't understand, so is not fatal.
ARGS=$CLIARGS
fi
open --background "lungo:$ARGS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment