Make a cup of coffee with Git

I created my own Git command to brew my morning coffee.
Register or Login to like
What is your favorite open source Java IDE?

Pixabay. CC0.

Git can do everything—except make your coffee. But what if it could?

Like most people, I already have a dedicated coffee brewing device listening to HTCPCP requests. All that is left is to hook Git up to it.

The first step is to write the client code, using httpx:

>>> import httpx
>>> result = httpx.request("BREW", "http://localhost:1111/")
>>> result.text
'start'

Ah, nothing nicer than a coffee pot starting to brew. You need to do a few more steps to make this available to git.

A proper way to do it would be to put this in a package and use pipx to manage it. For now, install httpx into your user environment:

$ pip install --user httpx

Then put this code in a script:

#!/usr/bin/env python
# This script should be in ~/.bin/git-coffee
# Remember to chmod +x ~/.bin/git-coffee
import httpx
result = httpx.request("BREW", "http://10.0.1.22:1111/")
result.raise_for_status()
print(result.text)

Make sure that ~/.bin is in your path:

$ (echo $PATH | grep -q ~/.bin) || echo "Make sure to add ~/.bin to your path!"

Finally, enjoy as your git command allows you to enjoy your morning coffee:

$ git coffee
start

The finer things in life

Python, Git, and coffee are a good combination for any open source programmer or user. I leave the exercise of implementing a coffee brewing terminal to you (maybe you have a spare Raspberry Pi looking for a purpose?) If you don't have a coffee machine configured for HTTP requests, then at the very least, you've learned how easy it is to use Python and the httpx module to make HTTP call requests. So go get yourself a coffee. You've earned it!

Tags
Moshe sitting down, head slightly to the side. His t-shirt has Guardians of the Galaxy silhoutes against a background of sound visualization bars.
Moshe has been involved in the Linux community since 1998, helping in Linux "installation parties". He has been programming Python since 1999, and has contributed to the core Python interpreter. Moshe has been a DevOps/SRE since before those terms existed, caring deeply about software reliability, build reproducibility and other such things.

1 Comment

Maybe I'm missing something, but how does "git" come into this example? Is the script being saved as "git" - or are you registering a new sub-command?

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.