DEV Community

Cover image for i3wm, Twitter, and Cursing Developers
Jase
Jase

Posted on

i3wm, Twitter, and Cursing Developers

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 from Brasil and brought my attention to a bot they mentioned that parses publicly available commit messages containing curses from GitHub and posts them anonymously to the Twitter account @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 using your distribution's package manager or you can starting with an i3 pre-installed distribution like Manjaro - i3 - This will be the distribution I will primarily refer to for this article.

(2.) Sign up for a Twitter Developers Account, start a Developer App, and issue Consumer Key and Consumer Secret keys.

(3.) Install and configure Twurl using the Consumer Key and Consumer Secret retreived from the Twitter APP.

(4.) Install ./jq

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

cp -v /etc/i3status.conf ~/.i3
Enter fullscreen mode Exit fullscreen mode

(7.) Create our script file.

touch ~/.i3/gitlost.sh
Enter fullscreen mode Exit fullscreen mode

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

vim ~/.i3/gitlost.sh
Enter fullscreen mode Exit fullscreen mode
#!/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
Enter fullscreen mode Exit fullscreen mode

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

chmod +x ~/.i3/gitlost.sh
Enter fullscreen mode Exit fullscreen mode

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

vim ~/.i3/config
Enter fullscreen mode Exit fullscreen mode
...
bar {
    ...
    status_command ~/.i3/gitlost.sh
    ...
}
...
Enter fullscreen mode Exit fullscreen mode

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

$mod+Shift+r
Enter fullscreen mode Exit fullscreen mode

Now you should see the most recent message posted to @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!

Top comments (1)

Collapse
 
asto profile image
astodev

you win, i quit.