<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jase</title>
    <description>The latest articles on DEV Community by Jase (@jase).</description>
    <link>https://dev.to/jase</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F94561%2Fd29a1499-4134-47fd-b5ac-491171c7ae6d.jpeg</url>
      <title>DEV Community: Jase</title>
      <link>https://dev.to/jase</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jase"/>
    <language>en</language>
    <item>
      <title>i3wm, Twitter, and Cursing Developers</title>
      <dc:creator>Jase</dc:creator>
      <pubDate>Mon, 08 Feb 2021 03:50:24 +0000</pubDate>
      <link>https://dev.to/jase/i3wm-twitter-and-cursing-developers-1ip8</link>
      <guid>https://dev.to/jase/i3wm-twitter-and-cursing-developers-1ip8</guid>
      <description>&lt;p&gt;They can be found in messages, images, film, and other, usually electronic mediums. Easter eggs coined by Steve Wright Director of Software Development at Atari Consumer Division during the the Atari 2600 Era when programmer Warren Robinett hid his initials in the seminal 1970 video game Adventure.&lt;/p&gt;

&lt;p&gt;Today the phenomenon can be found in pop culture including TV Shows like Fringe where small details (i.e. paint color splash) lead into the main plot point of the following episode, A Han Solo carbon figurine hidden by the cast in a scene of each episode of Jos Whedon's Firefly, or the plethora of details being discovered by fans within the MCU (Marvel Universe).&lt;/p&gt;

&lt;p&gt;Myself, and my colleagues have been known to also hide details of some joke or situation we are making fun of in our naming conventions for variables and files, print messages to the browsers console when the Konami code is entered, or in our commit messages.&lt;/p&gt;

&lt;p&gt;That brings us to the purpose of this article. Sometime ago my wife was listening to the &lt;a href="https://jovemnerd.com.br/nerdcast/"&gt;Nerdcast&lt;/a&gt; from Brasil and brought my attention to a &lt;a href="http://gitlost.net/"&gt;bot&lt;/a&gt; they mentioned that parses publicly available commit messages containing curses from GitHub and posts them anonymously to the Twitter account &lt;a href="https://twitter.com/gitlost"&gt;@gitlost&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I was amused by this so as a proof-of-concept I decided to see if I could display these messages within my i3bar with i3status.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements and Setup
&lt;/h2&gt;

&lt;p&gt;(1.) Install &lt;a href="https://i3wm.org/downloads/"&gt;i3wm, i3bar, and i3status&lt;/a&gt; using your distribution's package manager or you can starting with an i3 pre-installed distribution like &lt;a href="https://manjaro.org/downloads/community/i3/"&gt;Manjaro - i3&lt;/a&gt; - This will be the distribution I will primarily refer to for this article.&lt;/p&gt;

&lt;p&gt;(2.) Sign up for a &lt;a href="https://developer.twitter.com/en"&gt;Twitter Developers Account&lt;/a&gt;, start a &lt;a href="https://developer.twitter.com/en/docs/apps/overview"&gt;Developer App&lt;/a&gt;, and issue &lt;a href="https://developer.twitter.com/en/docs/authentication/oauth-1-0a"&gt;Consumer Key and Consumer Secret&lt;/a&gt; keys.    &lt;/p&gt;

&lt;p&gt;(3.) Install and configure &lt;a href="https://github.com/twitter/twurl"&gt;Twurl&lt;/a&gt; using the Consumer Key and Consumer Secret retreived from the Twitter APP.  &lt;/p&gt;

&lt;p&gt;(4.) Install &lt;a href="https://stedolan.github.io/jq/download/"&gt;./jq&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(5.) Locate the i3 config file for your user. For Manjaro-i3 this is &lt;code&gt;~/.i3/config&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;(6.) Copy &lt;code&gt;/etc/i3status.conf&lt;/code&gt; into the ~/.i3/ (~/.config/i3 Debian/Ubuntu)_ directory. This step is optional. I use 3 screens on my system and like to customise each screen with its own status configuration &lt;em&gt;(i.e. i3status-HDMI1.conf, i3status-HDMI2.conf etc...)&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; /etc/i3status.conf ~/.i3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(7.)  Create our script file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch&lt;/span&gt; ~/.i3/gitlost.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(8.) Write our script that will retrieve the tweets using your favourite text editor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vim ~/.i3/gitlost.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/sh&lt;/span&gt;

gitlost&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;GITLOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;twurl &lt;span class="s2"&gt;"/1.1/statuses/user_timeline.json? 
    screen_name=gitlost&amp;amp;include_rts=false&amp;amp;count=1"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="nv"&gt;GITLOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$GITLOST&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | jq &lt;span class="s1"&gt;'.[] | .text'&lt;/span&gt; | &lt;span class="nb"&gt;sed&lt;/span&gt; 
    &lt;span class="s1"&gt;'s/"//g'&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

i3status &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="nv"&gt;$HOME&lt;/span&gt;/.i3/i3status.conf | &lt;span class="k"&gt;while&lt;/span&gt; :
&lt;span class="k"&gt;do
    &lt;/span&gt;gitlost
    &lt;span class="nb"&gt;read &lt;/span&gt;line
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$GITLOST&lt;/span&gt;&lt;span class="s2"&gt; | &lt;/span&gt;&lt;span class="nv"&gt;$line&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit &lt;/span&gt;1
    &lt;span class="nb"&gt;sleep &lt;/span&gt;3600
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets take a look at what is happening. First we define &lt;br&gt;
our shell interpreter &lt;code&gt;#!/bin/sh&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then a function &lt;code&gt;gitlost() {}&lt;/code&gt;. containing the &lt;br&gt;
variable &lt;code&gt;GITLOST&lt;/code&gt; which holds our &lt;code&gt;twurl&lt;/code&gt; command &lt;br&gt;
for retrieving the latest tweet from the &lt;a href="https://twitter.com/gitlost"&gt;@gitlost&lt;/a&gt; twitter account.  &lt;/p&gt;

&lt;p&gt;After that the variable &lt;code&gt;GITLOST&lt;/code&gt; is defined a second &lt;br&gt;
time except this time echoing itself back into itself &lt;br&gt;
with some additional piped commands. I do this to keep &lt;br&gt;
data retrieval and processing separate. &lt;/p&gt;

&lt;p&gt;The first pipe &lt;code&gt;| jq '.[] | .text'&lt;/code&gt; is used to parse &lt;br&gt;
the JSON object retrieved by the &lt;code&gt;twurl&lt;/code&gt; command for &lt;br&gt;
the "text" property. This contains our message part of &lt;br&gt;
the tweet. We dispose of the rest.&lt;/p&gt;

&lt;p&gt;The second pipe &lt;code&gt;| sed 's/"//g'&lt;/code&gt; to remove the '"' &lt;br&gt;
characters from the string.&lt;/p&gt;

&lt;p&gt;Afterwords I call the &lt;code&gt;i3status&lt;/code&gt; command with the &lt;br&gt;
argument &lt;code&gt;-c ~/.i3/i3status.conf&lt;/code&gt; to load my custom &lt;br&gt;
configuration file which is then piped into a infinite &lt;br&gt;
&lt;code&gt;while :&lt;/code&gt; loop.&lt;/p&gt;

&lt;p&gt;Within the loop the &lt;code&gt;gitlost&lt;/code&gt; function is called &lt;br&gt;
loading the &lt;code&gt;GITLOST&lt;/code&gt; variable with data, then &lt;code&gt;read &lt;br&gt;
line&lt;/code&gt; which loads the output from the &lt;code&gt;i3status&lt;/code&gt; &lt;br&gt;
command to the variable &lt;code&gt;$line&lt;/code&gt;, and finally we echo &lt;br&gt;
all this out or exit with general errors.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;sleep 3600&lt;/code&gt; (1 Hour) command is added in order to &lt;br&gt;
not overload the twitter app with too many requests. For &lt;br&gt;
my setup I output this to a bar that does not require &lt;br&gt;
the information to be updated often. &lt;/p&gt;

&lt;p&gt;(9.) Make our script executable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x ~/.i3/gitlost.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(10.) Update the i3 configuration file to use our script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vim ~/.i3/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;...
bar &lt;span class="o"&gt;{&lt;/span&gt;
    ...
    status_command ~/.i3/gitlost.sh
    ...
&lt;span class="o"&gt;}&lt;/span&gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(11.) Finally reload the window manager (i3).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$mod&lt;/span&gt;+Shift+r
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you should see the most recent message posted to &lt;a href="https://twitter.com/gitlost"&gt;@gitlost&lt;/a&gt; within your i3bar.&lt;/p&gt;

&lt;p&gt;As this is a very simple script it should not be very hard to modify it to change the source, use it with i3blocks, conky, or anything else.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;

</description>
      <category>i3</category>
      <category>github</category>
      <category>twitter</category>
      <category>shell</category>
    </item>
  </channel>
</rss>
