A command-line Twitter client

Command Line – Rainbow Stream

© Lead Image © pixxart, 123RF.com

© Lead Image © pixxart, 123RF.com

Article from Issue 242/2021

If you prefer to work from the command line, Rainbow Stream offers a quick and flexible Twitter client.

Twitter and similar microblogging services are usually accessed from the desktop or a web browser. A rare exception is Rainbow Stream [1], which runs from the command line. Like most command-line interface (CLI) applications, it requires some learning, but once you are familiar with it, Rainbow Stream proves surprisingly quick and flexible, as well as a useful way to keep your hands on the keyboard to reduce repetitive stress injuries. With tweeting, navigation, filtering, and other functions accessible through a brief command, Rainbow Stream is a mostly complete Twitter client that is in some ways more efficient than many desktop alternatives. Overall, it is reminiscent of Alpine, the email client that was common on mainframes a couple of decades ago.

You will not find Rainbow Stream in the repositories of most distributions. The reason seems to be because it installs using pipenv, Python's dependency manager. You may already have most of the required packages installed, but to confirm enter the command:

sudo apt-get install python-dev libjpeg libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev python-pip pythonX

Currently, you need Python 2.7 or higher (although in the next release, the oldest supported version will be 3.6). To install, enter

pip install rainbowstream


pip3 install rainbowstream

depending on the Python version you are using (Figure 1).

Figure 1: Installing Rainbow Stream with Python's pipenv.

Alternatively, you can install Rainbow Stream using virtualenv, as described in the documentation [2].

To use Rainbow Stream, run a Twitter account and enter the command rainbowstream. If you have not already authorized Rainbow Stream to use that Twitter account, Rainbow Stream will open your web browser for you to obtain an authorization number to enter at the command line (Figure 2). Strangely, in Fedora, you are given a chance to choose the Twitter account to use, while in Debian Rainbow stream chooses one of your existing accounts apparently at random.

Figure 2: Authorization is required for encryption reasons. Copy the authorization number from the web browser and paste it into the terminal.

After authorization, Rainbow Stream notifies you about any development news, the version you are using, and any errors in setup (Figure 3). Your stream is immediately available. The default theme is brightly color-coded, with the tweeter's name in orange, their Twitter handle in green, how long ago they posted in blue, and so on. Pay special attention to the ID, which you will need to interact with the tweet (Figure 4).

Figure 3: Rainbow Stream notifies you of development news, the version number you are running, and any errors in setup.
Figure 4: Rainbow Stream's default theme is brightly color-coded.

Basic Navigation

Rainbow Stream can quickly fill the screen. At times, you may want to press the p key to pause the stream if you want to focus on Rainbow Stream's help or the currently displayed tweets. When you are ready, pressing r will unpause the screen. You can also press c to clear the current display completely. Before you settle down to read, you may want to type h to look at the help (Figure 5). No prompt is available – just type the command in the terminal. To exit, press the q key.

Figure 5: Rainbow Stream's help displays a list of commands.

Navigation and filtering are where Rainbow Stream excels. In Twitter's default web interface, navigating may involve scrolling, followed by selecting from the navigation pane on the left of the screen, and possibly more scrolling. By contrast, in Rainbow Stream, you can scroll using the arrow keys, but this is not the most efficient method of getting around. It is far easier to use Tab autocompletion. Better yet, you can navigate by typing brief commands and then pressing the Enter key. All commands can be entered alone, but you can append some commands with a string of letters to narrow the topic, a specific Twitter tag to view, or a number to indicate the number of tweets to display. After being on Twitter for more than a few moments, you might want to use me NUMBER to reduce the amount of scrolling you have to do.

Rainbow Stream supports all of Twitter's basic features. With the command trend, you can view the popular tweets on Twitter, filtering the response with a single word. Alternatively, s STRING searches Twitter for people and topics. When you have located an account, whois @ACCOUNT shows the account's profile and view @TAG NUMBER the account's timeline. For those who are curious about their own Twitter presence, mentions NUMBER show tweets from others that mention you, while notification shows your notifications since you started Rainbow Stream. You also can refer back to your own tweets (last one first) with me NUMBER. And if you get lost, home NUMBER will return you to your timeline.

Basic Tweeting

To tweet, press t, followed by the text of the tweet. No quotation marks are required. Rainbow Stream will not post a duplicate tweet, nor will it tweet more than 144 characters – which is the old (not current) limit. Should you post a longer tweet, Rainbow Stream will post only 144 characters and drop the rest with no warning. The same limitations apply to any retweet or any other form of retweeting.

However, to retweet, you have to add the ID of the original tweet. For example, rt 11 retweets the tweet in the current tweet with that ID. For your convenience, the ID is reprinted alongside your retweet. You can use quote COMMENT ID to retweet a message with your own mandatory comment, or you can see a list of all retweets with rt ID, followed by an optional number of retweets to display, or conversation ID to show the complete conversation in which the retweeted message appears.

Other basic commands include fav ID to make a tweet a favorite, or ufav ID to unfavorite a tweet. Similarly, with share ID, you can copy a link, and image ID uploads an image in your default image viewer. In addition, with open ID, you can open a tweet in your default browser – which can be a convenient alternative to searching or scrolling to find the tweet.

You can scan Direct Messages (DMs) with the inbox command, using thread ID to show a complete thread and trash ID to remove a message. The command list will show which DM lists you belong to, and list home will ask you for the name of a list whose timeline you wish to display. You can use list sub and list unsub to manage your subscriptions and list add and list rm to edit the people on lists that you run.

Curious about your followers? You can view a complete list with ls fl. Similarly, ls fr displays the people you are following. You can add a follower with fl @ACCOUNT or unfollow with ufl @ACCOUNT. Should someone become obnoxious, you can mute them (mute @ACCOUNT) or block them (block @ACCOUNT). Conversely, you can unmute (unmute @ACCOUNT) or unblock (unblock @ACCOUNT) them if you change your mind. Spam accounts can be reported with report @ACCOUNT.

None of these operations is unique. You can get the same functionality in Twitter's default web browser. However, these operations are faster in Rainbow Stream, requiring no copying and pasting or deleting with the mouse. The commands can take time to learn, but almost all are consistent in their structure, which makes them easier to learn than their sheer number might suggest.

Configuration and the Interactive Shell

Rainbow Stream installs with five multicolored themes. The command theme lists the theme, showing monokai as the current theme (Figure 6). To change the theme, enter theme THEME. For more detailed configuration, you can edit ~/.rainbow_config.json (Figure 7). Most of the approximately 30 options in .rainbow_config can be set to true or false. Most options do things like set the number of tweets to display in a given circumstance, the order in which information for each tweet is displayed, or how long the app can be inactive before it hangs up. Other options set things such as the format for date and time. The .rainbow_config file overrides the app's default.conf file. Should the format become invalid because of edits, Rainbow Stream will still start, and you can overwrite rainbow_config to try adding customization again.

Figure 6: Rainbow Stream offers five themes. An asterisk marks the current theme.
Figure 7: You can customize Rainbow Stream by editing ~/.rainbow_config.json.

Since Rainbow Stream is a Python interactive shell, it can also run most other scripts designed for an interactive shell. For example, you can use it as a calculator by using +, -, *, and / for basic operands. You can also use cal to display a calendar for the current month (Figure 8). This functionality can sometimes save you the trouble of switching from the terminal where you are running Rainbow Stream to the desktop.

Figure 8: Rainbow Stream can run Python interactive shell scripts like cal.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More