Tag Archives: Xmonad

Using DZEN with Xmonad to view Currently Active Network Shares

Currently Xmonad is my window manager of choice, because it’s clean, functional, and removes all the unnecessary crap that most modern desktops usually come with by default.

Although Xmonad is very cool, there are still some things that it’s lacking as far as functionality. Much of this is made up for by the use of Xmobar, Trayer, and other Xmonad compatible plugins and applications. I recently came across another one of these applications, and found it to be an exciting find. The tool is called Dzen.

Dzen is a desktop messaging tool which allows you to easily write some useful scripts, and have the output of those scripts become part of your desktop interface. Many examples of how this works are available on the Dzen webite, but some examples are as follows:

  • CPU Monitoring graphs
  • dmesg log monitoring
  • Notification of system events which are commonly found in syslog
  • E-mail or twitter alerts shown on your desktop as they come in
  • Custom calendar alerts
  • and much more..

Now this idea is not new – I remember there being a project called “OSD” (on-screen display) which essentially allows you to do the same thing. However, I think OSD was meant as more of an single message notification system, rather than the way that Dzen works, with master and slave windows, and the ability to implement menus, etc.

In any case, I decided to give Dzen a try, and am happy with the tool that I’ve been able to whip up. For the longest while, I wanted the ability for my xmonad environment to tell me, at a quick glance, what network mounts and removable devices I currently have mounted. I’m sure that this kind of information is easily available on many bloated desktops, including GNOME and KDE, but I was looking for something simple, small and configurable. Didn’t find it, so I ended up writing my own – with the help of Dzen.

Here are a couple of screenshots of how it looks:

Dzen “Active Mounts” widget (mouse out):
dzen-1

 

Dzen “Active Mounts” widget (mouse over):
dzen-2

 

I wrote the scripts fairly quickly, so I’m sure they could be written better, but I think they will provide those of you who are interested, a good example of how to implement a regularly updated notification widget with Dzen.

The scripts are written to check for changes in the mount list, and only update Dzen when a change is detected. It is written in two components:

1) A perl script which captures the mount information in the exact format that I want, and
2) a bash script which handles loading Dzen

Here’s the source code (perl script):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
 
# Written by J. Bobby Lopez <jbl@jbldata.com> - 27 Jan 2010
# Script to -be loaded- by the 'dzen-mounts.bash' script
# This script can also be run by itself, if you want to dump a
# custom plain-text table of your network shares or removable
# devices.
#
# This script is meant to be utilized the Dzen notification system
# Information on Dzen can be found at http://dzen.geekmode.org/
 
use strict;
use warnings;
 
use Data::Dumper;
use Text::Table;
 
my @types = qw( cifs ntfs davfs sshfs smbfs vfat );
 
sub getmounts
{
    my @valid_mounts; # to hold mounts we want
    my @all_mounts = split (/\n/, `mount`);
    foreach my $mount (@all_mounts)
    {
        foreach my $type (@types)
        {
            if ( $mount =~ m/$type/ )
            {
                push (@valid_mounts, $mount);
            }
        }
    }
    return @valid_mounts;
}
 
sub getsizes
{
    my @mounts = getmounts();
    my @list;
    foreach my $mount (@mounts)
    {
        my @cols = split (/\ /, $mount);
        my @df_out = split (/\n/, `df -h $cols[2]`);
        $df_out[1] .= $df_out[2] if defined($df_out[2]);
        $df_out[1] =~ s/[[:space:]]+/\ /;
	    my @df_cols = split (/[[:space:]]+/, $df_out[1]);
        push (@list, ([@df_cols]));
    }
    return @list;
}
 
my $tb = Text::Table->new(
	"Filesystem", "Size", "Used", "Avail", "Use%", "Mounted on"
);
$tb->load(getsizes());
print "Active Mounts\n";
print $tb;

And the bash script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
 
# Script to load Dzen with output from 'dzen-mounts.pl' script
# Written by J. Bobby Lopez <jbl@jbldata.com> - 27 Jan 2010
#
# This script utilizes the Dzen notification system
# Information on Dzen can be found at http://dzen.geekmode.org/
 
function mountlines
{
        LINES=`perl dzen-mounts.pl|wc -l`;
        echo "$LINES"
}
 
function freshmounts
{
        OUTPUT=`perl dzen-mounts.pl`;
        echo "$OUTPUT"
}
 
function rundzen
{
        OUTPUT=`freshmounts`;
        MOUNTLINES=`mountlines`;
        echo "$OUTPUT" | dzen2 -p -l "$MOUNTLINES" -u -x 500 -y 0 -w 600 -h 12 -tw 120 -ta l &
        PID=`pgrep -f "dzen2 -p -l $MOUNTLINES -u -x 500 -y 0 -w 600 -h 12 -tw 120 -ta l"`;
        echo "$PID"
}
 
function killdzen
{
        PID="$1"
        if [ ! "$PID" ]; then
            MOUNTLINES=`mountlines`;
            PID=`pgrep -f "dzen2 -p -l $MOUNTLINES -u -x 500 -y 0 -w 600 -h 12 -tw 120 -ta l"`;
        fi
 
        if [ "$PID" ]; then
            #echo "Killing $PID..";  # DEBUG STATEMENT
            kill "$PID";
        fi;
}
 
function checkchanges
{
    while true; do
        NEW=`freshmounts`;
        #echo "$NEW - new";  # DEBUG STATEMENT
        if [ "$OLD" != "$NEW" ]; then
            killdzen "$PID";
            rundzen;
            #echo "$PID started";  # DEBUG STATEMENT
            OLD="$NEW";
            #echo "$OLD - old updated"  # DEBUG STATEMENT
        fi
        sleep 1;
    done
}
 
checkchanges

You can also download the scripts in a tgz archive here. Enjoy!

Xmonad: For Hardcore Desktop User Interface Efficiency

Long time linux/unix hackers know of the plethora of window managers and user interfaces that have been and currently are available for Linux and BSD operating systems.  I’ve had great times in the past trying out different window managers such as Elightenment, Sawfish, Black Box, IceWM, xfwm, KDE, Gnome,  and others.  These days the two most popular which are shipped with the more popular distributions (Fedora, Ubuntu) are KDE and Gnome.

However, I remember back in the day when I was using a Enlightenment, or Ratpoison, doing strange and cool things (at the time) like applying transparencies to your windows and modifying the the window borders to be anything but normal and square.

I used to share screenshots of my desktop with others who are also into “desktop eyecandy”, where I’d have floating or docked window maker panels, and monitoring applets anchored to the desktop as if they were part of the background wallpaper.. and this was around 1999.  It was fun times.

One of the more interesting things that I was into at the time was increasing the efficiency and usability of my desktop by trying to reduce the need to reach for my mouse.  I’ve been very accustomed to this already being user of vi and the GNU Screen terminal multiplexor, but the window managers never seemed to try to attain the same level “hacker cool”.  That is, of course until I came across Ratpoision. Ratpoison was exactly what the name implied, a window manager that killed your dependency on the mouse (or rat).  It was awesome, but it wasn’t scalable and didn’t evolve much to keep up with modern technological advancements and requirements such as multi-monitor support.

I recently thought that those days were long lost, until I recently had the urge to streamline my desktop environment.  I now have a 28″ Monitor, and was certain there was a better way to interact with the desktop than the standard Ubuntu/Gnome environment.  So I went looking.  I started looking of course at things I was already familiar with – I looked up Ratpoision to see if there were any major improvements over the years.

I took a look at a Ratpoison again, but it was showing it’s age.  I looked at it’s successor, Stumpwm, but I didn’t feel the love.  Then I tried out Xmonad, created by Spencer Janssen, Don Stewart, and Jason Creighton – and written in Haskell.  I immediately fell in love.

If you haven’t used GNU Screen, Gnome Multi-Terminal, Ratpoision, or any minimalist Window Manager before, then it will be hard to explain why Xmonad is worth your time.  Instead, visit the Xmonad website here: http://www.xmonad.org/

Here are some suggestions on how get Xmonad working on Ubuntu 8.10:

Install Xmonad:

apt-get install xmonad

We’re going to create another X window session, so that we don’t mess with your existing one. That way, if you don’t like Xmonad, you can go back to using your existing window manager without worrying about breaking your configuration.

Set up your second X window session. Press “ctrl + alt + f2” – this will take you to the command-line terminal where you will start your second X session. Start the session using following command:

xinit -- :1 vt12

This will start up another X session which will sit at virtual terminal 12 – meaning that you have to press ‘ctrl-alt-F12′ to get to it.

Once at your new X session, you should see nothing more than an plain old xterm window. Type “xmonad’, and the terminal window should now be maximized. Xmonad is now running.

Type ‘man xmonad’ to view the help documentation on how to use it.  It’s pretty straight forward, and a joy to use!