<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>*JJ</title><link href="http://blog.jdotjdot.com/" rel="alternate"></link><link href="http://blog.jdotjdot.com/feeds/tag/bashweather.atom.xml" rel="self"></link><id>http://blog.jdotjdot.com/</id><updated>2014-05-22T23:16:55-04:00</updated><entry><title>Include the weather in your bash prompt!</title><link href="http://blog.jdotjdot.com/2014/05/include-the-weather-in-your-bash-prompt/" rel="alternate"></link><updated>2014-05-22T23:16:55-04:00</updated><author><name>JJ</name></author><id>tag:blog.jdotjdot.com,2014-05-22:2014/05/include-the-weather-in-your-bash-prompt/</id><summary type="html">&lt;p&gt;About a third of the way into Hacker School, I got myself entrenched in a rather unusual project&amp;#8212;trying to figure out how to get an automatically updated weather icon into my Bash prompt, doing it purely in Bash for practical (and aesthetic)&amp;nbsp;reasons.&lt;/p&gt;
&lt;p&gt;I called it &lt;a href="https://github.com/jdotjdot/BashWeather"&gt;BashWeather&lt;/a&gt;.&lt;/p&gt;
&lt;div style="/* background-color: lightgray; */ padding: 10px 0; border-radius: 15px; text-align: center;border: 3px solid lightgray;margin: 0 10% 15px 10%;"&gt;

    &lt;div style="max-width: 90%; margin: auto;"&gt;

    &lt;img alt="BashWeather Screenshot" src="http://jdotjdot.github.io/images/bashweather%20screenshot.png" &gt;
    &lt;img alt="BashWeather Screenshot" src="http://jdotjdot.github.io/images/bashweather%20screenshot%202.png"&gt;

&lt;/div&gt;

&lt;div style="text-align: center; font-style: italic;"&gt;&lt;span class="caption"&gt;Screenshots of a sample terminal session with BashWeather&lt;/span&gt;&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;/p&gt;
&lt;div style="font-size: 150%; text-align: center; /* margin-left: 5%; */"&gt;☃☽☀︎☁☂☔&lt;/div&gt;

&lt;div style="text-align: center; font-style: italic;"&gt;Weather character palette&lt;/div&gt;

&lt;/div&gt;

&lt;p&gt;There are a number of configurable options, including the&amp;nbsp;following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How often to wait between weather&amp;nbsp;updates&lt;/li&gt;
&lt;li&gt;The default character to be supplied in the event that the weather isn&amp;#8217;t&amp;nbsp;available&lt;/li&gt;
&lt;li&gt;The method to use to determine where in the world the computer is located.  Options are to use &lt;span class="caps"&gt;IP&lt;/span&gt; address, to use the built-in Mac locator if available, or to supply the city and country in a string when calling the&amp;nbsp;script.&lt;/li&gt;
&lt;li&gt;Allowable timeout for the &lt;span class="caps"&gt;HTTP&lt;/span&gt; requests BashWeather&amp;nbsp;makes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I learned quite a bit from this project about Bash functions, scoping, some of Bash&amp;#8217;s oddities (behavior of brackets, globbing, needing to quote variables, etc.), and some of the nitty-gritty details of Bash variables.  Since a lot of global variables were required by the script to keep track of state, like how long it&amp;#8217;s been since the last check and whether or not internet is available, I was very careful to pollute the global namespace as little as possible, which was an interesting exercise given that Bash functions &lt;a href="http://www.linuxjournal.com/content/return-values-bash-functions"&gt;can&amp;#8217;t actually return values to the caller&lt;/a&gt; in the way you&amp;#8217;d traditionally think about&amp;nbsp;it.&lt;/p&gt;
&lt;h3&gt;But&amp;#8230;&amp;nbsp;why?&lt;/h3&gt;
&lt;p&gt;I couldn&amp;#8217;t think of anything to do at Hacker School for a bit, and I was about to head outside to get a cup of coffee to clear my head, and I noticed that it was raining and got very upset that I didn&amp;#8217;t have an umbrella with me.  I almost always forget to bring my umbrella, and I used to use an &lt;a href="http://www.ifttt.com"&gt;&lt;span class="caps"&gt;IFTTT&lt;/span&gt;&lt;/a&gt; recipe that sent me a Gchat whenever it started to rain.  Unfortunately, with the advent of Hangouts, it was eventually&amp;nbsp;deprecated.&lt;/p&gt;
&lt;p&gt;I liked the Gchat recipe because it alerted me both on my computer and on my phone.  Considering how to replace it, I started thinking about what I look at more than anything else&amp;#8212;and realized the one and only answer there was my Bash prompt.  I&amp;#8217;m always looking at the command line, one way or another, or at least have it open&amp;#8212;and the decision was&amp;nbsp;made.&lt;/p&gt;
&lt;p&gt;From then on, I would know the&amp;nbsp;weather.&lt;/p&gt;
&lt;h3&gt;But would you really ever look at the weather in your&amp;nbsp;prompt?&lt;/h3&gt;
&lt;p&gt;When I started telling people about it at Hacker School I did encounter a bit of skepticism, usually along the lines&amp;nbsp;of:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Why would you ever need the weather in your&amp;nbsp;prompt?&lt;/p&gt;
&lt;p&gt;Come on, you&amp;#8217;re never actually going to use&amp;nbsp;that.&lt;/p&gt;
&lt;p&gt;&amp;#8230;etc.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I got this reaction from one person in particular, and we then sat down to start pairing on a quick question that we were trying to resolve&amp;#8212;I think possibly something to do with BashWeather&amp;nbsp;itself.&lt;/p&gt;
&lt;p&gt;We&amp;#8217;d been working not even two minutes when we turned to the prompt and he saw the umbrella (☂) in the prompt and exclaimed, &amp;#8220;Oh no, is it raining? I didn&amp;#8217;t&amp;nbsp;realize!&amp;#8221;&lt;/p&gt;
&lt;p&gt;&amp;#8230;and then he realized what had happened, and then I&amp;nbsp;grinned.&lt;/p&gt;
&lt;h3&gt;And now, the&amp;nbsp;code&lt;/h3&gt;
&lt;p&gt;The full script, with instructions, can be found at the &lt;a href="https://github.com/jdotjdot/BashWeather"&gt;Github repository&lt;/a&gt;.  It is currently fully functional, though still a work in progress.  I&amp;#8217;ll be doing a longer post shortly on how I structured BashWeather from a scoping perspective, since I found the architecture required of a large Bash script to be very different and very&amp;nbsp;interesting.&lt;/p&gt;</summary><category term="hackerschool"></category><category term="bash"></category><category term="weather"></category><category term="bashweather"></category></entry></feed>