{"id":63319,"date":"2022-04-01T09:02:00","date_gmt":"2022-04-01T09:02:00","guid":{"rendered":"https:\/\/www.cryptocabaret.com\/?p=63319"},"modified":"2022-04-01T09:02:00","modified_gmt":"2022-04-01T09:02:00","slug":"make-a-cup-of-coffee-with-git","status":"publish","type":"post","link":"https:\/\/www.cryptocabaret.com\/?p=63319","title":{"rendered":"Make a cup of coffee with Git"},"content":{"rendered":"<p><span class=\"field field--name-title field--type-string field--label-hidden\">Make a cup of coffee with Git<\/span><br \/>\n<span class=\"field field--name-uid field--type-entity-reference field--label-hidden\"><a title=\"View user profile.\" href=\"https:\/\/opensource.com\/users\/moshez\" class=\"username\">Moshe Zadka<\/a><\/span><br \/>\n<span class=\"field field--name-created field--type-created field--label-hidden\">Fri, 04\/01\/2022 &#8211; 03:00<\/span><\/p>\n<div data-drupal-selector=\"rate-node-69531\" class=\"rate-widget-thumbs-up\">\n<div class=\"rate-thumbs-up-btn-up rate-thumbs-up-btn-up vote-pending\">Up<\/div>\n<div class=\"rate-score\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to like.<\/div>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item\">\n<p>Git can do everything\u2014except make your coffee. But what if it could?<\/p>\n<p>Like most people, I already have a dedicated coffee brewing device listening to <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc2324\" target=\"_blank\" rel=\"noopener\">HTCPCP<\/a>\u00a0requests. All that is left is to hook Git up to it.<\/p>\n<p>The first step is to write the client code, using <a href=\"https:\/\/opensource.com\/article\/22\/2\/getting-started-httpx\">httpx<\/a>:<\/p>\n<\/p>\n<div class=\"embedded-resource-list callout-float-right\">\n<div class=\"field field--name-title field--type-string field--label-hidden field__item\">More on Git<\/div>\n<div class=\"field field--name-links field--type-link field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/resources\/what-is-git?intcmp=7013a000002CxqLAAS\">What is Git?<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheet-git?intcmp=7013a000002CxqLAAS\">Git cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheet-markdown?intcmp=7013a000002CxqLAAS\">Markdown cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/git?intcmp=7013a000002CxqLAAS\">New Git articles<\/a><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<pre>\n<div class=\"geshifilter\"><div class=\"python geshifilter-python\"><span class=\"sy0\">&gt;&gt;&gt;<\/span> <span class=\"kw1\">import<\/span> httpx<br><span class=\"sy0\">&gt;&gt;&gt;<\/span> result <span class=\"sy0\">=<\/span> httpx.<span class=\"me1\">request<\/span><span class=\"br0\">(<\/span><span class=\"st0\">\"BREW\"<\/span><span class=\"sy0\">,<\/span> <span class=\"st0\">\"http:\/\/localhost:1111\/\"<\/span><span class=\"br0\">)<\/span><br><span class=\"sy0\">&gt;&gt;&gt;<\/span> result.<span class=\"me1\">text<\/span><br><span class=\"st0\">'start'<\/span><\/div><\/div><\/pre>\n<p>Ah, nothing nicer than a coffee pot starting to brew. You need to do a few more steps to make this available to <code>git<\/code>.<\/p>\n<p>A proper way to do it would be to put this in a package and use <code>pipx<\/code>\u00a0to manage it. For now, install <code>httpx<\/code>\u00a0into your user environment:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span>pip <span class=\"kw2\">install<\/span> <span class=\"re5\">--user<\/span> httpx<\/code><\/span><\/pre>\n<p>Then put this code in a script:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"python geshifilter-python\"><span class=\"co1\">#!\/usr\/bin\/env python<\/span><br><span class=\"co1\"># This script should be in ~\/.bin\/git-coffee<\/span><br><span class=\"co1\"># Remember to chmod +x ~\/.bin\/git-coffee<\/span><br><span class=\"kw1\">import<\/span> httpx<br>\nresult <span class=\"sy0\">=<\/span> httpx.<span class=\"me1\">request<\/span><span class=\"br0\">(<\/span><span class=\"st0\">\"BREW\"<\/span><span class=\"sy0\">,<\/span> <span class=\"st0\">\"http:\/\/10.0.1.22:1111\/\"<\/span><span class=\"br0\">)<\/span><br>\nresult.<span class=\"me1\">raise_for_status<\/span><span class=\"br0\">(<\/span><span class=\"br0\">)<\/span><br><span class=\"kw1\">print<\/span><span class=\"br0\">(<\/span>result.<span class=\"me1\">text<\/span><span class=\"br0\">)<\/span><\/div><\/div><\/pre>\n<p>Make sure that <code>~\/.bin<\/code>\u00a0is in your path:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"br0\">(<\/span><span class=\"kw3\">echo<\/span> <span class=\"re1\">$PATH<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">grep<\/span> <span class=\"re5\">-q<\/span> ~<span class=\"sy0\">\/<\/span>.bin<span class=\"br0\">)<\/span> <span class=\"sy0\">||<\/span> <span class=\"kw3\">echo<\/span> <span class=\"st0\">\"Make sure to add ~\/.bin to your path!\"<\/span><\/code><\/span><\/pre>\n<p>Finally, enjoy as your <code>git<\/code>\u00a0command allows you to enjoy your morning coffee:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">$ <span class=\"kw2\">git<\/span> coffee<br>\nstart<\/div><\/div><\/pre>\n<h2>The finer things in life<\/h2>\n<p>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&#8217;t have a coffee machine configured for HTTP requests, then at the very least, you&#8217;ve learned how easy it is to use Python and the <code>httpx<\/code>\u00a0module to make HTTP call requests. So go get yourself a coffee. You&#8217;ve earned it!<\/p>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-field-article-subhead field--type-text-long field--label-hidden field__item\">\n<p>I created my own Git command to brew my morning coffee.<\/p>\n<\/div>\n<div class=\"field field--name-field-lead-image field--type-entity-reference field--label-hidden field__item\">\n<article class=\"media media--type-image media--view-mode-caption\">\n<div class=\"field field--name-field-media-image field--type-image field--label-hidden field__item\">  <img decoding=\"async\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/04\/java-coffee-mug.jpg\" width=\"520\" height=\"292\" alt=\"What is your favorite open source Java IDE?\" title=\"What is your favorite open source Java IDE?\" loading=\"lazy\"><\/div>\n<div class=\"field field--name-field-caption field--type-text-long field--label-hidden caption field__item\"><span class=\"caption__byline\">Image by: <\/span><\/p>\n<p>Pixabay. CC0.<\/p>\n<\/div>\n<\/article>\n<\/div>\n<div class=\"field field--name-field-tags field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/git\" hreflang=\"en\">Git<\/a><\/div>\n<\/p><\/div>\n<div class=\"hidden field field--name-field-listicle-title field--type-string field--label-hidden field__item\">What to read next<\/div>\n<div class=\"field field--name-field-default-license field--type-list-string field--label-hidden field__item\"><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><br \/>\n        <img decoding=\"async\" alt=\"Creative Commons License\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/04\/cc-by-sa-4.png\" title=\"This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.\"><\/a>This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.<\/div>\n<section class=\"field field--name-field-comments field--type-comment field--label-hidden comment-wrapper\">\n<div class=\"comments__count\">\n<div class=\"login\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to post a comment.<\/div>\n<\/p><\/div>\n<\/section>\n<p class=\"wpematico_credit\"><small>Powered by <a href=\"http:\/\/www.wpematico.com\" target=\"_blank\" rel=\"noopener\">WPeMatico<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Make a cup of coffee with Git Moshe Zadka Fri, 04\/01\/2022 &#8211; 03:00 Up Register or Login to like. Git can do everything\u2014except make your coffee. But what if it could? Like most people, I already have a dedicated coffee brewing device listening to HTCPCP\u00a0requests. All that is left is to hook Git up to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":63320,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307],"tags":[],"class_list":["post-63319","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source"],"_links":{"self":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/63319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=63319"}],"version-history":[{"count":0,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/63319\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/media\/63320"}],"wp:attachment":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=63319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=63319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=63319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}