Tag Archives: shell

Rainbow Terminal Text With Lolcat

Like seeing rainbows all over the place? Does it make you especially happy to have a colorful terminal? Yeah, me too. There’s a little Ruby program called lolcat and it will help you out (in the happiness department).

lolcat_rainbow_terminal_colorful_pandora_cli_pianobar

Steps to a super colorful terminal:

  1. Install lolcat in one of two ways.
    1. As a Ruby gem using the standard Ruby utility.  gem install lolcat
    2. Through your system’s package manager.  sudo apt-get install lolcat
  2. Pipe your program through lolcat.
    • cat cool_file.txt | lolcat

That’s really it. The only problem I’ve come across is when piping through a program that is still in control of the terminal output.  My main example is with Pianobar, the Pandora CLI app. It doesn’t actually break anything, you just can’t see the last line of the terminal. This means the song progress can’t be seen, and it can be a problem if the user is expected to enter information. I’ve gotten used to it though, it’s really worth it for the colors!

Have fun with rainbows all up in your face!

git_help_lolcat_rainbow_colors_cli_terminal

 

Python Snippet: Get Terminal Width

There is a wonderful command on UNIX systems to return the width of the current terminal. Enter  tput cols and see for yourself! Tput can actually provide a lot of different info by querying the terminfo database. Really all I’ve needed though is ‘cols’ for columns.

I was writing a Python CLI app, and wanted to format and print output in a nice table. To do that (without downloading a table printing module) I had to know how much space was available for printing. Can’t make a nice-looking set of data if every other line is being wrapped!

Here is a simple function that returns the width of whatever terminal is running the script. Subprocess is the most current built-in Python module for running system commands. It contains a selection of different functions each with many optional parameters, depending on the complexity of your needs. Using subprocess.check_output() is the way to go if you are looking to get back the output of a command. The  check_output() function has a whole slew of accepted arguments, but in this simple instance we need only one: a list containing command to run and the arguments to pass to it.

The first exception will be raised if the system returns an error when trying to execute the tput command. The second exception will be raised if the command (in our case tput) has a problem with the given argument ( cols). If nothing goes wrong, the output will be a nice whole number that you can use to determine exactly how many characters can be printed per line!

Have you ever needed to know the width of your terminal? If you have any questions please feel free to ask in the comments below!

Here’s a link to this code snippet on Github Gists: terminal_width.py

Lessons Learned : All About Icons And Shortcuts

Here’s the latest grouping of my favorite bookmarks and why I think you should check them out!

  • Add Sublime Text to Ubuntu launcher – Ubuntu’s launcher can be pretty finicky when trying to lock new icons to it. I’ve had problems for a while getting Sublime Text’s launcher to stick on my laptop. This concise article shows how to make a proper Unity launcher that shows up in Applications and will stay nicely on the launcher dock. On my machine I installed to my preferred spot of /opt/ as opposed to this author’s ~/My Programs/. Also, instead of the uglyish default, I used this custom icon by Nate Beaty:

    sublime text icon by nate beaty

 

  • 60 Beautiful CSS-Sprite Social Media Icons – This is the set of icons I used for the menu on the very blog you are reading. They were put together and provided with CSS coordinates by Brandon Setter. The lovely icons themselves were designed and provided for free by Icon Dock. Thanks to both for adding flair to my theme!
    Update September 9, 2013: I have since changed the theme and social media icons.
    socialmediacsspriteiconset

 

  • Add shell aliases to ‘sudo’ commands – I am growing a decent list of shell aliases in my .bash_profile and there have been a few cases where I’ve been frustrated by them not being available to ‘sudo’. It’s not that often I run across a use case, but I did today with ‘ufw’. I wanted to alias it to ‘firewall’ but it must always be run as root. Now my alias works thanks to: