Skip to content

Instantly share code, notes, and snippets.

@Imater
Created January 29, 2020 07:08
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 Imater/295c93f43aef9fe32841e4764b2a8c4e to your computer and use it in GitHub Desktop.
Save Imater/295c93f43aef9fe32841e4764b2a8c4e to your computer and use it in GitHub Desktop.
> tomat 25 'Название дела'
#!/usr/bin/env bash
SLEEP_DURATION=${SLEEP_DURATION:=1} # default to 1 second, use to speed up tests
progress-bar() {
local duration
local columns
local space_available
local fit_to_screen
local space_reserved
space_reserved=6 # reserved width for the percentage value
duration=${1}
columns=$(tput cols)
space_available=$(( columns-space_reserved ))
if (( duration < space_available )); then
fit_to_screen=1;
else
fit_to_screen=$(( duration / space_available ));
fit_to_screen=$((fit_to_screen+1));
fi
already_done() { for ((done=0; done<(elapsed / fit_to_screen) ; done=done+1 )); do printf "▇"; done }
remaining() { for (( remain=(elapsed/fit_to_screen) ; remain<(duration/fit_to_screen) ; remain=remain+1 )); do printf " "; done }
percentage() { printf "| %s%%" $(( ((elapsed)*100)/(duration)*100/100 )); }
clean_line() { printf "\r"; }
for (( elapsed=1; elapsed<=duration; elapsed=elapsed+1 )); do
columns=$(tput cols)
space_available=$(( columns-space_reserved ))
already_done; remaining; percentage
sleep "$SLEEP_DURATION"
clean_line
done
clean_line
}
SECOND=${1}
TASK_NAME=${2}
NOW=`date +"%Y-%m-%d %T"`
checkbox="[v]"
start=$SECONDS
function cleanup {
end=$SECONDS
duration=$((( end - start )/60))
if ((duration < SECOND))
then
say "Жаль!"
checkbox="[ ]"
fi
# osascript -e "set Volume output muted true"
# SwitchAudioSource -s 'Built-in Output'
osascript -e "tell application \"System Events\" to keystroke \"D\" using {command down, shift down, option down, control down}"
echo "${NOW} | ${checkbox} ${TASK_NAME} | ${duration} мин." >> !done.txt
osascript -e "tell application \"System Events\" to keystroke \"P\" using {shift down, control down}"
}
trap cleanup EXIT
osascript -e "tell application \"System Events\" to keystroke \"D\" using {command down, shift down, option down, control down}"
osascript -e "tell application \"System Events\" to keystroke \"P\" using {shift down, control down}"
# osascript -e "set Volume output muted false"
# SwitchAudioSource -s 'CA DacMagicXS 2.0'
defaults write org.eyebeam.SelfControl BlockDuration -int ${SECOND}
defaults write org.eyebeam.SelfControl HostBlacklist -array facebook.com news.ycombinator.com vk.com youtube.com zen.yandex.ru yandex.ru facebook.com lenta.ru livejournal.com www.youtube.com youtube.com mail.google.com
defaults read org.eyebeam.SelfControl
sudo /Applications/SelfControl.app/Contents/MacOS/org.eyebeam.SelfControl $(id -u $(whoami)) --install
say "Начали!"
echo "${TASK_NAME} ${SECOND} мин."
progress-bar $((SECOND*60))
say "Вы молодец, так держать!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment