Make a cup of coffee with Git

Make a cup of coffee with Git
Moshe Zadka
Fri, 04/01/2022 – 03:00

Up
Register or Login to like.

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!

I created my own Git command to brew my morning coffee.

What is your favorite open source Java IDE?

Pixabay. CC0.


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

Powered by WPeMatico

Author: dasuberworm

Standing just over 2 meters and hailing from о́стров Ратма́нова, Dasuberworm is a professional cryptologist, entrepreneur and cage fighter. When he's not breaking cyphers and punching people in the face, Das enjoys receiving ominous DHL packages at one of his many drop sites in SE Asia.

Share This Post On