Linux Blog

Awesome Piping

Filed under: General Linux,Quick Linux Tutorials — Kaleb at 8:01 am on Wednesday, April 23, 2008

Have you ever wanted to try a tiling window manager. But maybe you don’t want to deal with DWM and its bad config setup that forces you to recompile the app each time you change the config.

I suggest to you AwesomeWM. It was originally based on DWM, however now it is completely on its own. For those of you who don’t know, tiling window mangers are window managers that basically allow you to use ALL of y
our screen. If screen landscape is scarce on your box i suggest a tiling window manager. How do they do this? Its all about managing windows baby. What they do is they make every window you open full screen. that
s right FULL screen and if you open up more then one window in one virtual desktop it cuts them in half so that they are each using half the screen, and so on.

But this article is not about tiling window managers exactly it is about piping in awesome. The AwesomeWM has a status bar that you can edit which by default holds a list of your “tags” (virtual desktops however with a little bit different technique) and a window list of all the windows open on your current tag. However you can edit what is on this status bar with the .awesomerc. Now your asking yourself what can I put on i
t, does it have special keywords like conky or something? The answer is no. it works nothing like conky, however if you do it right you can completely replace conky.

Now how to do this. Open up your .awesomerc file with your favorite editor (i suggest vi or vim, and if you don’t know those why are you even at this site). Now you will see a bunch of lame stuff right, well you need to scroll down to the “status bar” section, this section strangely holds all the things that you will place on your status bar (the status bar section is repeatable so you can have more then one status bar as long as the name is changed).

Now with me I do not like having a list of running windows on my status bar, so I just remove that section,but I do like to have a clock on my status bar, I would assume you would like it to however I don’t know.

At first look it will seem a little complicated to make just a simple clock, but its actually not that bad once you get the hang of it.

What you need to do, for a clock, is create a “textbox” section (yes the time is TEXT strange eh).
It should look something like

textbox clock
{
text=” ”
}

the space between the “” is supposed to be a space so don’t worry about that. Now after you have this set up you are done messing with your .awesomerc. “clock” is now a keyword that you can use to pipe the clock t
o that part of your status bar.

Next what your going to want to do is create a little shell script for rendering your clock it should look something like:

#!/bin/bash

echo “0 widget_tell mystatusbar clock text `date +”%A %B %d, %Y %l:%M %p”`” | awesome-client

Now that is really complicated right. Well not really.

Honestly I have no idea what “0 widget_tell” does, I am assuming is just telling the status bar what to do.

Next in the list you have “mystatusbar” that is the name of your status bar, you should probably know the name of it.

Next should be obvious “clock” is the section of your status bar you want the data to be ported to.

After that comes “text” this just tells it that it is text and not some other type of data.

Then, inside the “ is the command you want to run. This is just the date command that has been modified to output the date in a specific format, it will output the date and time like this “Friday April 18, 2008
2:23 PM”

If you want it in a different way look at “man date” for help (its really simple).

Finally in the command you have “| awesome-client” this will pipe the command to awesome.

Now you need to have this script run on a regular basis, some people do this as a “while true” thing in there .xinit or something however since this is just a clock that only tells me minutes I use the crontab to
run this script every minute. A crontab to run this every minute should look like:
*/1 * * * * ~/scripts/clock.sh
Do all of this and you should have an up and running clock in no time. And like I said before you can put anything you want into this. Even graphics. So now that you know the basic stuff go make a pretty status bar.

Kaleb Porter

porterboy55@yahoo.com

http://kpstuff.servebeer.com (website is temporarily down)

RSS Feeds

Filed under: Shell Script Sundays — Kaleb at 11:43 am on Sunday, April 20, 2008

The other day I was playing around with AwesomeWM and I wanted to have the newest article from digg.com/linux_unix to be displayed in the statusbar. I thought to myself:

“I roughly know how RSS works, so I should be able to do this.”

It turns out it was extremely easy to do.

First how does RSS work. It’s easy just an xml file that gets downloaded with a list of the articles on the site. Well that’s pretty simple so I wrote a little script that will do all the things I need.

First I needed to download the list

wget -c http://digg.com/rss/indexlinux_unix.xml

done with that. Now for what I wanted and to make it a little cleaner i moved this file:

mv indexlinux_unix.xml ~/.news

this way it was in a file that i can easily access.

After that it was just some simple editing of the file using sed. If you don’t know much about sed I suggest you read up on it. It is an extremely powerful tool for quick editing and scripting. For the editing of
the file it was actually quite simple:

cat ~/.news | grep “<title>” | sed -e ‘s/<[/]title>//’ | sed -e ‘s/<title>//’ | sed -e ’2,2 !d’

now no worries I will explain this its actually quite simple.

I will assume you know what cat ~/.news does but if you don’t, it outputs the contents of the file until the end of the file.

| grep “<title>” is a very important part of the command. As I looked at the xml file i realized that i would get a simple list of all the articles if I greped the title. However thats not all.

It was a very messy output with <title> at the beginning and </title> at the end. Nobody wants to look at that, what I wanted was the text in between. | sed -e ‘s/<[/]title>//’ will get rid of the </title> in the line. I am almost certain that | sed -e ‘s/<\/title>//’ would have done that same thing but you can test that if you want. It needs to be done like this because “/” is a special character so it needs to be escaped.

The next part | sed -e ‘s/<title>//’ should be self explanatory. Basically it just gets rid of the <title> in the line. So now using the first 3 pipes you will get a nice pretty list of all the articles.

This is not what we wanted though. We wanted the newest article. so that’s why we use | sed -e ’2,2 !d’. This command will cut out everything except the second line in the list. “Hmm but why the second line Kaleb?”
well because while creating this script I found that the first <title> line was the line that told me where I was getting this information from. So it was http://digg.com/linux_unix now I don’t want that. so I went with the second line for the first article. Easy right.

Now as I mentioned at the begining of this article, I wanted to make this give me a clickable link for the awesome statusbar. I will go over awesome piping later this week but basically the only information you will need. Is to go threw your xml file for your RSS feed and find out between what tags the link for your article is and use the above command to show you that link instead of the title then have Firefox open that
link (or whatever browser you use). It was a very simple thing to do.

Kaleb Porter

porterboy55@yahoo.com

http://kpstuff.servebeer.com (website currently down)