Skip to content

Instantly share code, notes, and snippets.

@komidore64
Last active September 26, 2022 16:48
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 komidore64/7c182480b460f6d32c7b70886fa64ccb to your computer and use it in GitHub Desktop.
Save komidore64/7c182480b460f6d32c7b70886fa64ccb to your computer and use it in GitHub Desktop.
Quick script implementation of the Pomodoro technique. You can hook these scripts into timers, or use it for ideas with your own implementation.
#!/usr/bin/env python3
import click
import os
RC_FILE = os.path.join(os.environ['HOME'], '.cache', 'pomodoro.rc')
def initialize_rc():
if not os.path.exists(RC_FILE):
write_rc(0)
def write_rc(contents):
with open(RC_FILE, 'w') as rc:
rc.write(str(contents).strip())
def read_rc():
initialize_rc()
with open(RC_FILE, 'r') as rc:
contents = rc.read()
return contents.strip()
def display_cycles():
click.echo(read_rc())
@click.group(invoke_without_command=True)
@click.pass_context
def cli(ctx):
if ctx.invoked_subcommand is None:
display_cycles()
@click.option(
'-q',
'--quiet',
help='Supress all output.',
is_flag=True,
default=False
)
@cli.command()
def cycle(quiet):
cycles = int(read_rc()) + 1
write_rc(cycles)
if not quiet:
display_cycles()
@cli.command()
def reset():
if os.path.exists(RC_FILE):
os.remove(RC_FILE)
if __name__ == '__main__':
cli()
#!/usr/bin/env bash
${HOME}/bin/pomo cycle --quiet
completed=$(${HOME}/bin/pomo)
message="Pomodoro cycles completed: ${completed}"$'\n'
if [ ${completed} -ge 4 ]; then
adj='long'
else
adj='short'
fi
message+="Take a ${adj} break."
gxmessage -center -ontop -sticky "${message}"
#!/usr/bin/env bash
${HOME}/bin/pomo reset
message="Long break is complete."$'\n'
message+="Get back to work!"
gxmessage -center -ontop -sticky "${message}"
#!/usr/bin/env bash
message="Short break is complete."$'\n'
message+="Get back to work, pleb!"
gxmessage -center -ontop -sticky "${message}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment