Skip to content

Instantly share code, notes, and snippets.

@tarruda
Last active September 15, 2024 14:18
Show Gist options
  • Save tarruda/ec4601f420f0ef0ab7a99d6582f90f0a to your computer and use it in GitHub Desktop.
Save tarruda/ec4601f420f0ef0ab7a99d6582f90f0a to your computer and use it in GitHub Desktop.
Shfokus wrapper cron script. See https://github.com/rioastamal/shfokus for more info
#!/bin/bash
# Get the current hour and minute (24-hour format)
current_time=$(date +"%H%M")
# Get the current day of the week (1 = Monday, 7 = Sunday)
current_day=$(date +"%u")
# Check if already blocked
if grep -q "shfokus_begin" /etc/hosts; then
blocked=true
else
blocked=false
fi
# during weekdays, between 09:30 and 17:30, block distracting websites
if [ "$current_day" -ge 1 ] && [ "$current_day" -le 5 ] && [ "$current_time" -ge 0930 ] && [ "$current_time" -lt 1730 ]; then
if [ "$blocked" = "false" ]; then
shfokus.sh -a block
fi
else
if [ "$blocked" = "true" ]; then
shfokus.sh -a unblock
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment