i3wm, Twitter, and Cursing Developers
Tags: i3, github, twitter, shell
Published: 2021-02-08 03:50:24

---
title: i3wm, Twitter, and Cursing Developers
published: true
description: Display gitlost twitter bot messages in the i3bar.
tags: i3, github, twitter, shell
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/jxogmluing61fagt2tcl.png
---

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.

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).

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.

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

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.

## Requirements and Setup

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

(2.) Sign up for a [Twitter Developers Account](https://developer.twitter.com/en), start a [Developer App](https://developer.twitter.com/en/docs/apps/overview), and issue [Consumer Key and Consumer Secret](https://developer.twitter.com/en/docs/authentication/oauth-1-0a) keys.    

(3.) Install and configure [Twurl](https://github.com/twitter/twurl) using the Consumer Key and Consumer Secret retreived from the Twitter APP.  

(4.) Install [./jq](https://stedolan.github.io/jq/download/)

(5.) Locate the i3 config file for your user. For Manjaro-i3 this is ``~/.i3/config``. 

(6.) Copy ``/etc/i3status.conf`` 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 _(i.e. i3status-HDMI1.conf, i3status-HDMI2.conf etc...)_ 

```shell
cp -v /etc/i3status.conf ~/.i3
``` 

(7.)  Create our script file.    

```shell  
touch ~/.i3/gitlost.sh
```  

(8.) Write our script that will retrieve the tweets using your favourite text editor.  

```shell
vim ~/.i3/gitlost.sh
```

```shell
#!/bin/sh

gitlost() {
	GITLOST=$(twurl "/1.1/statuses/user_timeline.json? 
	screen_name=gitlost&include_rts=false&count=1");)
	GITLOST=$(echo "$GITLOST" | jq '.[] | .text' | sed 
	's/"//g')
}

i3status -c $HOME/.i3/i3status.conf | while :
do
	gitlost
	read line
	echo "$GITLOST | $line" || exit 1
	sleep 3600
done
```

Lets take a look at what is happening. First we define 
our shell interpreter ``#!/bin/sh``.

Then a function ``gitlost() {}``. containing the 
variable ``GITLOST`` which holds our ``twurl`` command 
for retrieving the latest tweet from the [@gitlost] 
(https://twitter.com/gitlost) twitter account.  

After that the variable ``GITLOST`` is defined a second 
time except this time echoing itself back into itself 
with some additional piped commands. I do this to keep 
data retrieval and processing separate. 

The first pipe ``| jq '.[] | .text'`` is used to parse 
the JSON object retrieved by the ``twurl`` command for 
the "text" property. This contains our message part of 
the tweet. We dispose of the rest.

The second pipe ``| sed 's/"//g'`` to remove the '"' 
characters from the string.

Afterwords I call the ``i3status`` command with the 
argument ``-c ~/.i3/i3status.conf`` to load my custom 
configuration file which is then piped into a infinite 
``while :`` loop.

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

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

(9.) Make our script executable.

```shell
chmod +x ~/.i3/gitlost.sh
```

(10.) Update the i3 configuration file to use our script.  

```shell
vim ~/.i3/config
```

```shell
...
bar {
	...
	status_command ~/.i3/gitlost.sh
	...
}
...
```

(11.) Finally reload the window manager (i3).

```shell
$mod+Shift+r
```

Now you should see the most recent message posted to [@gitlost](https://twitter.com/gitlost) within your i3bar.

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.

Enjoy!