paritybit.ca

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit c5d10ac938259ecbd7895da93dfd09a612fabfc6
parent 2fda69acf43cacea52cbe664fe81c5c1fba2baa1
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Tue, 26 Oct 2021 10:28:20 -0400

Publish new blog post

Diffstat:
Mpages/blog.md | 1+
Apages/blog/a-git-workflow-with-claws-mail.md | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpublic/feeds/sitewide-feed.xml | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apublic/img/claws-mail-actions.png | 0
Mpublic/sitemap.xml | 1+
Apublic/vid/claws-mail-git.webm | 0
6 files changed, 205 insertions(+), 0 deletions(-)

diff --git a/pages/blog.md b/pages/blog.md @@ -26,6 +26,7 @@ src="/img/feed-icon.png" width="15" height="15" alt="Click for RSS"/> Subscribe </form> <ul> + <li>2021-10-26 <a href="blog/a-git-workflow-with-claws-mail">A Git Workflow With Claws Mail</a></li> <li>2021-08-18 <a href="blog/laptops-suck-why-i-might-get-a-macbook-air">Laptops Suck (or Why I Might Get a New MacBook Air)</a></li> <li class="blog-star">2021-08-05 <a href="blog/mastodon-is-dead-long-live-misskey">Mastodon Is Dead, Long Live Misskey 🍮</a></li> <li>2021-02-17 <a href="blog/migrating-from-nginx-to-openbsd-httpd-and-relayd">Migrating from nginx to OpenBSD's httpd and relayd</a></li> diff --git a/pages/blog/a-git-workflow-with-claws-mail.md b/pages/blog/a-git-workflow-with-claws-mail.md @@ -0,0 +1,102 @@ +## A Git Workflow With Claws Mail + +[//]: # "Detailing how I have set up claws mail to allow me to work with Git using the standard email workflow." + +[//]: # "main.min.css" + +[//]: # + +<div class="byline"> +<b>Written By:</b> Jake Bauer | + <b>Posted:</b> 2021-10-26 | + <b>Last Updated:</b> 2021-10-26 +</div> + +When sending or receiving patches to or from git repositories, I prefer to use +`git send-email`. I find this workflow more efficient and less distracting than +jumping to a web interface to create a pull request. Plus, it's not dependent on +having an account wherever a repository is hosted. + +I used to use [aerc](https://aerc-mail.org/) as my email client, but have since +switched to [Claws Mail](https://www.claws-mail.org/) as I find TUIs with +multiple windows, tabs, and panes to be awkward to use. However, aerc came with +some really nice features for software development which aren't available in +Claws Mail. Watch the video at the link for aerc above to see those features in +action. + +Sending emails with `git send-email` is easy and switching to Claws Mail +required no changes to my workflow because it does not interact with an email +client at all. On the other hand, patches sent to me do end up in my email +client so I needed a way to quickly and easily apply the patches I receive. +Luckily, it's fairly easy to do this with Claws Mail since it is quite +extensible. + +First, I needed to write a small script to parse the email and extract the +repository name from the subject line so the patch can be applied to the +correct repository. Then, the script `cd`s into the repository and uses `git am` +to apply the patch. Here is the script: + +``` +#!/bin/sh + +projectsDir="$HOME/Documents/projects" +patchFile="/tmp/patch" + +IFS='' +while read -r line; do + echo "$line" >> "$patchFile" + if echo -n "$line" | grep -q "^Subject:"; then + repo=$(echo "$line" | grep -o '\[PATCH .*\]' | cut -d' ' -f2 | tr -d ']') + fi +done + +echo "Applying patch to: $projectsDir/$repo" +cd "$projectsDir"/"$repo" && git am "$patchFile" +rm "$patchFile" +``` + +There are two variables of note: `projectsDir` and `patchFile`. `patchFile` is +simply a temporary file where the script keeps the contents of the email. +`projectsDir` is the directory in which the script will look to find your +repositories. If you keep your repositories in a different location (e.g. +`$HOME/Projects`) then you should edit this variable to point to that location. + +Another important note is that the script looks for the repository using the +text that follows the word "PATCH" in the subject. When sending emails with `git +send-email`, you should specify the project name after the "PATCH" text so the +person to which you are emailing the patch knows at a glance which repository +your patch is for. If this is done correctly, a subject line will look something +like: + +``` +Subject: [PATCH aerc] Fix whitespace in documentation +``` +The script is licensed under the Unlicense, by the way. + +After writing the script, I needed to add an Action in Claws Mail. This can be +done through the top menu by navigating to "Configuration > Actions..." and +creating an action to run a shell command. Prefixing the shell command with the +pipe `|` symbol will tell Claws Mail to pipe the contents of the body of the +email on which the action is invoked to the command. This is what my action +looks like: + +<figure> + <a href="/img/claws-mail-actions.png"><img src="/img/claws-mail-actions.png" alt="A screenshot of the Actions configuration menu with an action configured with the menu name 'Git Apply Patch' and the Command '|git-apply-patch'."/></a> +</figure> + +I also bound this action to a [custom keyboard +shortcut](https://www.claws-mail.org/faq/index.php/Interface#How_can_I_change_the_key-bindings_.28hot-keys.29_in_Claws_Mail.3F) +so I can press a key combination which will apply the patch. After running a +shell command, Claws Mail helpfully opens up a window displaying the output of +the command so I can see whether or not the command failed and what went wrong. + +Here is an example of me applying a patch where you can first see a successfully +applied patch, followed by what it looks like when the patch fails to apply: + +<video src="/vid/claws-mail-git.webm" alt="A demonstration of applying a git +patch by invoking the action on a patch email in Claws Mail." controls>Your +browser does not support the video tag.</video> + +So there you have it: a clean and easy way to apply git patches using Claws +Mail. It's even faster than using aerc too, since I only have to type a single +keyboard shortcut instead of typing out whole commands. diff --git a/public/feeds/sitewide-feed.xml b/public/feeds/sitewide-feed.xml @@ -7,6 +7,107 @@ <description>The feed that covers all notable additions, updates, announcements, and other changes for the entire paritybit.ca website.</description> <item> + <title>A Git Workflow With Claws Mail</title> + <link>https://www.paritybit.ca/blog/a-git-workflow-with-claws-mail</link> + <guid>https://www.paritybit.ca/blog/a-git-workflow-with-claws-mail</guid> + <pubDate>Tue, 26 Oct 2021 10:25:33 -0400</pubDate> + <description><![CDATA[<h2 id="A%20Git%20Workflow%20With%20Claws%20Mail">A Git Workflow With Claws Mail</h2> + +<div class="byline"> +<b>Written By:</b> Jake Bauer | + <b>Posted:</b> 2021-10-26 | + <b>Last Updated:</b> 2021-10-26 +</div> + +<p>When sending or receiving patches to or from git repositories, I prefer to use +<code>git send-email</code>. I find this workflow more efficient and less distracting than +jumping to a web interface to create a pull request. Plus, it&#8217;s not dependent on +having an account wherever a repository is hosted.</p> + +<p>I used to use <a href="https://aerc-mail.org/">aerc</a> as my email client, but have since +switched to <a href="https://www.claws-mail.org/">Claws Mail</a> as I find TUIs with +multiple windows, tabs, and panes to be awkward to use. However, aerc came with +some really nice features for software development which aren&#8217;t available in +Claws Mail. Watch the video at the link for aerc above to see those features in +action.</p> + +<p>Sending emails with <code>git send-email</code> is easy and switching to Claws Mail +required no changes to my workflow because it does not interact with an email +client at all. On the other hand, patches sent to me do end up in my email +client so I needed a way to quickly and easily apply the patches I receive. +Luckily, it&#8217;s fairly easy to do this with Claws Mail since it is quite +extensible.</p> + +<p>First, I needed to write a small script to parse the email and extract the +repository name from the subject line so the patch can be applied to the +correct repository. Then, the script <code>cd</code>s into the repository and uses <code>git am</code> +to apply the patch. Here is the script:</p> + +<pre><code>#!&#47;bin&#47;sh + +projectsDir="$HOME&#47;Documents&#47;projects" +patchFile="&#47;tmp&#47;patch" + +IFS=&#39;&#39; +while read -r line; do + echo "$line" &#62;&#62; "$patchFile" + if echo -n "$line" | grep -q "^Subject:"; then + repo=$(echo "$line" | grep -o &#39;\[PATCH .*\]&#39; | cut -d&#39; &#39; -f2 | tr -d &#39;]&#39;) + fi +done + +echo "Applying patch to: $projectsDir&#47;$repo" +cd "$projectsDir"&#47;"$repo" &#38;&#38; git am "$patchFile" +rm "$patchFile" +</code></pre> + +<p>There are two variables of note: <code>projectsDir</code> and <code>patchFile</code>. <code>patchFile</code> is +simply a temporary file where the script keeps the contents of the email. +<code>projectsDir</code> is the directory in which the script will look to find your +repositories. If you keep your repositories in a different location (e.g. +<code>$HOME&#47;Projects</code>) then you should edit this variable to point to that location.</p> + +<p>Another important note is that the script looks for the repository using the +text that follows the word &#8220;PATCH&#8221; in the subject. When sending emails with <code>git +send-email</code>, you should specify the project name after the &#8220;PATCH&#8221; text so the +person to which you are emailing the patch knows at a glance which repository +your patch is for. If this is done correctly, a subject line will look something +like:</p> + +<pre><code>Subject: [PATCH aerc] Fix whitespace in documentation +</code></pre> + +<p>The script is licensed under the Unlicense, by the way.</p> + +<p>After writing the script, I needed to add an Action in Claws Mail. This can be +done through the top menu by navigating to &#8220;Configuration &#62; Actions&#8230;&#8221; and +creating an action to run a shell command. Prefixing the shell command with the +pipe <code>|</code> symbol will tell Claws Mail to pipe the contents of the body of the +email on which the action is invoked to the command. This is what my action +looks like:</p> + +<figure> + <a href="/img/claws-mail-actions.png"><img src="/img/claws-mail-actions.png" alt="A screenshot of the Actions configuration menu with an action configured with the menu name 'Git Apply Patch' and the Command '|git-apply-patch'."/></a> +</figure> + +<p>I also bound this action to a <a href="https://www.claws-mail.org/faq/index.php/Interface#How_can_I_change_the_key-bindings_.28hot-keys.29_in_Claws_Mail.3F">custom keyboard +shortcut</a> +so I can press a key combination which will apply the patch. After running a +shell command, Claws Mail helpfully opens up a window displaying the output of +the command so I can see whether or not the command failed and what went wrong.</p> + +<p>Here is an example of me applying a patch where you can first see a successfully +applied patch, followed by what it looks like when the patch fails to apply:</p> + +<p><video src="/vid/claws-mail-git.webm" alt="A demonstration of applying a git +patch by invoking the action on a patch email in Claws Mail." controls>Your +browser does not support the video tag.</video></p> + +<p>So there you have it: a clean and easy way to apply git patches using Claws +Mail. It&#8217;s even faster than using aerc too, since I only have to type a single +keyboard shortcut instead of typing out whole commands.</p>]]></description> + </item> +<item> <title>Laptops Suck (or Why I Might Get a New MacBook Air)</title> <link>https://www.paritybit.ca/blog/laptops-suck-why-i-might-get-a-macbook-air</link> <guid>https://www.paritybit.ca/blog/laptops-suck-why-i-might-get-a-macbook-air</guid> diff --git a/public/img/claws-mail-actions.png b/public/img/claws-mail-actions.png Binary files differ. diff --git a/public/sitemap.xml b/public/sitemap.xml @@ -3,6 +3,7 @@ <url><loc>https://www.paritybit.ca</loc></url> <url><loc>https://www.paritybit.ca/home</loc></url> <url><loc>https://www.paritybit.ca/blog</loc></url> + <url><loc>https://www.paritybit.ca/blog/a-git-workflow-with-claws-mail</loc></url> <url><loc>https://www.paritybit.ca/blog/laptops-suck-why-i-might-get-a-macbook-air</loc></url> <url><loc>https://www.paritybit.ca/blog/mastodon-is-dead-long-live-misskey</loc></url> <url><loc>https://www.paritybit.ca/blog/migrating-from-nginx-to-openbsd-httpd-and-relayd</loc></url> <url><loc>https://www.paritybit.ca/blog/flip-phone-challenge-complete</loc></url> <url><loc>https://www.paritybit.ca/blog/flip-phone-challenge</loc></url> <url><loc>https://www.paritybit.ca/blog/gemini-is-up-and-running</loc></url> diff --git a/public/vid/claws-mail-git.webm b/public/vid/claws-mail-git.webm Binary files differ.