Another reason to love Linux: conky!

This is purely a nice-to-have sort of thing, but conky is a great app you can use with pretty much any distribution of Linux. What it is, is a command-line program that reads a configuration file, which puts live/updated information on your desktop:

image

Windows had this for a time in the form of “gadgets”, but that technology went away. Even if it didn’t, they were difficult and complicated to write. Conky, conversely is pretty simple. You can literally show anything you can imagine, and have it update as often as you want. Here’s a closer look at configuration I’ve been evolving:

image

By default, conky reads a .conkyrc file in your home directory. However, you can have several configs running. For example, something like this in the top right, but also show the weather in the bottom middle. That would be done with a separate config file.

The .conkyrc file has two sections. The top is for defaults and for general settings. Then, there is a “TEXT” line, and everything below that is a direct instruction of what to show on the desktop. The format of the tokens it uses is sort of like HTML, but not really. For example, to change the color of text, you’d do ${color white}this is white${color}. You’d think that the ${color} at the end means “this is the end of the color block”, but it really just means “go back to the default color”.

OK, so with that said, there are a zillion built-in things which you can show and lay out however you’d like. Here is the list of all conky objects.

Looking at the screenshot above, the code to show the time, date, then the word “System” with the line after it, and then the basic information below, is:

${color CDE0E7}${font OxygenSans:pixelsize=70}${time %l:%M %P}${font}
${hr 1}

${font OxygenSans:pixelsize=20}${time %A} $alignr${color white}${time %d}-${color CDE0E7}${time %b}-${color white}${time %Y}${font}

${color white}SYSTEM ${hr 3}${color}
Hostname: $alignr$nodename
Uptime: $alignr$uptime
Battery: ${alignr}${battery_percent BAT0}%
Processes: ${alignr}$processes ($running_processes running)

It looks like gibberish at first, but if you take it one piece at a time, it’s pretty simple to work with.

Network and VPN:
Since I use this on a couple of systems, I wanted to have this “just work” on most Linux distributions. Well, some distributions call the first Ethernet NIC “eth0” and others call it “enp1s0”. Similarly, some distributions call the first WiFi NIC “wlan0”, and others call it “wlp3s0”. So, wanted to account for that by seeing if the names of those devices were present on the system. In Linux “everything is a file”, so I can use the conky ${if_existing FILE} to go see if the various devices exist or not, and show them. For example:

${if_existing /proc/sys/net/ipv4/conf/eth0}
eth0: ${addr eth0}${color aaaaaa}
Down ${downspeed eth0} k/s ${alignr}Up ${upspeed eth0} k/s
${downspeedgraph eth0 25,107} ${alignr}${upspeedgraph eth0 25,107}
Total ${totaldown eth0} ${alignr}Total ${totalup eth0}${color}
${endif}

and, since I use VPN, I wanted a simple way to show whether I was connected to VPN or not. How do you do that? Well, there are a couple of ways. Since conky can execute arbitrary operating system commands, we can go look at the network route table. If there exists routes for “tun0”, which is the virtual tunnel adapter that comes online when you are connected to a VPN, then we assume VPN is up. If there are no routes, we assume VPN is down. So, we can “cat” (or, concatenate) the route file and then “grep” (or, search) for “tun0”. That is done with this bit of conky code:

${if_empty ${exec cat /proc/net/route | grep tun0}} ${else} ${endif}

I added some color too, but ultimately that results in something like this:

image

image

Maybe you are starting to see the potential here? This means that you can show almost anything you can imagine, on your desktop. One of the core settings is how often this should be refreshed. Since I’m showing processes, CPU %, etc – I update it every 2 seconds. But this, like everything else with conky, is completely configurable.

Using my conky config:
On any Debian-based distribution of Linux, just install conky:

sudo apt-get install conky

then, you can pull down my current .conkyrc file and save it as .conkyrc in your home directory:

wget -o ~/.conkyrc https://tinyurl.com/conky-rob

You can also just view that file too, here:

https://gist.github.com/RobSeder/ae1553beca3ae527cb51

finally, just run conky, turn on double-buffering, and have it run in the background:

conky -b -d

And you should now see something similar on your desktop. Please note though that I am using Kubuntu, so the default font I am using may not be available on your system – so you might need to change that?

Next Steps…
If you do a google image search for conky, you’ll see there are endless possibilities for the kinds of things you are show on your desktop, and creative ways they can be laid out. This is kind of a cool idea because your background can actually start being a useful, active part of your computing environment – instead of just sitting there like a freeloader!!

For me, a good concept is also adding the weather to the desktop. However, you need to find a decent, free weather service API. I did some basic research and found a couple. Once I get this figured out, I’ll do another blog post on it.

Meanwhile, if you have any good stuff to add from your .conkyrc, let me know!

Posted in Computers and Internet, General, Linux, Organization will set you free, Professional Development, Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 5 other followers

%d bloggers like this: