XMonad, Gnome, Ubuntu 11.10

October 17, 2011

Here’s how I have xmonad and gnome playing nicely on Ubuntu 11.10.

First, we’ll make a file for a new session in the log in manager. Xmonad probably ships with /usr/share/xsessions/xmonad.desktop. You should make /usr/share/xsessions/xmonad-gnome.desktop:

[Desktop Entry]
Name=XMonad GNOME
Comment=This session logs you into GNOME with the traditional panel
Exec=gnome-session --session=xmonad-gnome

So, this points the log in manager to a gnome session called xmonad-gnome. We’ll define that session in the file /usr/share/gnome-session/sessions/xmonad-gnome.session:

[GNOME Session]
Name=Xmonad session

The line DefaultProvider-windowmanager=xmonad-gnome is to use a custom start script. Instead of xmonad-gnome, you could just use xmonad and you’d be done. If you want this custom script, you need to make another file /usr/share/applications/xmonad-gnome.desktop

[Desktop Entry]

The line Exec=xmonad-start is calling my custom script. For me, I have xmonad-start in ~/bin/ which is part of my path.

In xmonad-start should be something like:

conky -c configfile &
otherstartupstuff.sh &

Personally, I can’t get conky to work correctly right now. If you are using gnome and xmonad in ubuntu 11.10 and have conky working, let me know what you did!

XMonad and Gnome

October 3, 2010

Hey there. This is how I am setting up XMonad to run with Gnome on my Ubuntu 10.04 install.

Presumably, this will work with most Gnome set-ups.

My desire is to have a session available from GDM that uses Gnome but with XMonad as my window manager. I’ll also be using xmobar. If you want to use xmonad and xmobar, you should be able to figure out how to install them on your own distribution.

So, I have everything installed. First thing I’m going to do is create a new session that is available in my GDM login. If you have installed XMonad, you likely have an xmonad.desktop in /usr/share/xsessions. This will just run an XMonad session. I want to run XMonad with Gnome so I’m going to copy this file to xmonad-gnome.desktop and edit it slightly so that it looks like this:

[Desktop Entry]
Comment=Lightweight tiling window manager

The difference is that the name is XMonad-Gnome. That’s what I’ll select at the sessions option at the GDM login. Another good name could be Gonad. Also, the Exec is now xmonad-gnome. xmonad-gnome is the name of an executable that I have to create. It will tell xmonad and gnome how to play together. We have to create this script ourselves and make sure it’s executable and somewhere in our path.

A safe place to put the xmonad-gnome script is in /usr/local/bin. I’m going to put mine in ~/bin because that’s where I sometimes keep little scripts. Also, if I ever need to change things I won’t need root access to edit it. Just make sure it’s in your path somewhere.

Here’s my xmonad-gnome file:

export WINDOW_MANAGER=xmonad
gconftool-2 -u /desktop/gnome/session/required_components/windowmanager
urxvtd -f -o &

Be careful here, “gconftool-2 -u /desktop/gnome/session/required_components/windowmanager” should be all on one line. WordPress may be trying to be pretty here and I don’t want to take the time to figure out how to keep this all on one line. Tell me in the comments!

The line urxvtd -f -o & is an example of a start up program. If you don’t have any that you know about, just ignore that line. If you have start up things (conky maybe?) you’ll probably want to call them here, or put them all in a start up file and then call that file here.

Ok. We are at the home stretch. Now we need to make our xmonad configuration. Your configuration should live in ~/.xmonad/xmonad.hs. This file, at minimum should look like this:

import XMonad
import XMonad.Util.EZConfig
import XMonad.Config.Gnome
main = xmonad $ gnomeConfig
{ terminal = "gnome-terminal" }

(IMPORTANT NOTE: It seems that wordpress is not interested in preserving white space. If you try these configs and they don’t work, try putting in some spaces where it makes sense. Or if you get stuck, write me in the comments and I’ll do my best to help you out.)

Feel free to try this out, now. Log out and log back in. Don’t forget to select XMonad-Gnome session at the log in. To get a terminal, hit Alt-Shift-Enter. It will be the typical gnome-terminal. You’ll also still have your panels. At this point you should look up XMonad’s default key bindings or make up your own configuration. I might eventually post my xmonad.hs especially if I get requests.

I don't know anything about haskell. I just picked up stuff here and there and recognized patterns.
This should be more than enough to get you started. Enjoy!

How to make animations with Gnuplot

June 7, 2009

This is how you do it:

set terminal gif animate delay 10

The delay 10 means 10*0.01 seconds between each image. Then, you just plot each subsequent image until your done. I normally write a bash script to do this sort of thing automatically, so here’s an example.

echo "clear" > plot.gpi
echo "reset" >> plot.gpi
echo "set terminal gif animate delay 10" >> plot.gpi
echo "set output \"animate.gif\"" >> plot.gpi
echo "set isosample 40" >> plot.gpi
echo "set hidden3d" >> plot.gpi
for i in `seq 0 ${MAX}`
echo "splot sin(${i}*x/${MAX})*cos(${i}*y/${MAX})" \
>> plot.gpi

So what I’m doing here is letting a bash script create a gnuplot script for me. Instead of writing out about a hundred different splots by hand, I let a for loop do that for me. Additionally, I specify a few things at the beginning.
So, put that code in a file somwhere.
Make it executable:chmod +x file
Then run it: ./file
Now, you should have a file plot.gpi that contains all the gnuplot commands.
Now open gnuplot: gnuplot
Then run the plot.gpi script: gnuplot> load 'plot.gpi'
And now you should have an animated gif creatively titled animation.gif.

When I do this in real life, I normally have a data file (perhaps generated with octave/matlab) with each time step separated by two blank lines. After two blank lines, gnuplot says we are on a new index so I can make my repeated plot line as something like:
for i ...; do echo "plot 'datafile' using 1:2 index ${i} with lines"; done etc…

biking and hiking in hyalite

May 10, 2009

After calling and wishing my mother a happy mother’s day, I went down to Hyalite for some snowshoeing. Hyalite canyon road is closed to motor vehicles from April 1st to May 15th for spring break up.

The good part is if you go up there you practically have the whole place to yourself. Concordantly, you can bike on a nice road without worrying about cars.

The bad part is that it has snowed appreciably on half the days the road has been car free making getting up there on a bike not always reasonable.

I went up once earlier, April 12. At that time, I didn’t have a blog so I couldn’t tell the internet about it. So, here is a quick synopsis. I had to do a significant amount of bike pushing to the reservoir and then I hiked back to grotto falls which was just a pile of snow at the time. I had really wanted to hike a bit up wildhorse creek trail because I think it has the signature Hyalite view, but I was post-holing to my waist every step. So I decided that I would bring snowshoes next time.

So today, I biked up with my snowshoes. It got cloudy eventually but I had gotton up there early enough to beat the clouds. The road was totally clear up to the reservoir and spotty past. I got up wildhorse to my view, snapped a few shots then came back down and headed off towards pallisade falls. The road that goes off to emerald lake trailhead does not get vehicle traffic/plowing over winter so the snow’s deep. I put my shoes back on and made it out to pallisade.

I was the only one out beyond the reservoir. On my way back, I saw two people at the reservoir and a good number of people making their way up. It’s kind of funny to see them all in their bike jersey’s and I have on boots and snowshoes on my back.

Here’s a picture from wildhorse and one of pallisade falls.

Cool Bash Prompt – Smiley

May 8, 2009

Here’s what my prompt looks like:

[mike@esme ~] :) echo "smiley bash prompt is cool" | grep -q smiley
[mike@esme ~] :) echo "smiley bash prompt is cool" | grep -q frowny
[mike@esme ~] :( not_a_real_command
-bash: not_a_real_command: command not found
[mike@esme ~] :( echo "echo is a real command"
echo is a real command
[mike@esme ~] :)

Above, grep looked for smiley and found it so it returned sucessfully and I got a happy smiley. Next, grep did not find any “frowney” so it returned “unsuccesfully” and I got a frowney. My prompt really does have color but I had to cheat and put it in the html for this demonstration.

To use this prompt, if you are using bash (if you don’t know, you probably are) you can put this into your .bashrc. That is in your home folder, there should be a file called .bashrc and if there’s not just create it. Make sure to comment any other definitions of the prompt (PS1) or just put this at the bottom of the file.

First you may as well define some colors to make it easy on you for playing around:

#Regular text color
#Bold text color
#background color

Now tell bash you want to run a particular function everytime it goes to write the prompt


Now, define the function smile_prompt

function smile_prompt
if [ "$?" -eq "0" ]
if [ $UID -eq 0 ]
#root user color
#normal user color
#hostname color
#regular color
#default color
PS1="[${UC}\u${RC}@${HC}\h ${RC}\W${DF}] ${SC}${DF} "

In addition to the colored smileys, my hostname and user are also colored with root being red. If you want root to use this, you can put it in /root/.bashrc as well.

How to set up Gmail Mutt and OfflineIMAP with multiple accounts part 3

May 3, 2009

This shall be an in depth look at how to set gmail with mutt and offlineimap using multiple gmail accounts.

This third part is how to set up mutt.

Part 1: Gmail
Part 2: offlineIMAP
Part 3: mutt

Setting up msmtp

Mutt is an interface for browsing mail. You can create mail in the program but mutt needs another program like msmtp to actually send the mail. In your home directory, we’ll need to create the file .msmtprc to specify the accounts from which we will be sending mail. Let me recall what accounts we have:

Accounts used under personal@gmail.com:

  • personal@gmail.com
  • student@school.edu
  • student@physics.school.edu

Accounts used under net@gmail.com

  • net@gmail.com

I’m mostly going to steal the config found in the Arch Linux Wiki.

In .msmtp we’ll start with our personal account:

account personal
host smtp.gmail.com
port 587
protocol smtp
auth on
from personal@gmail.com
user personal@gmail.com
password mypassword
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

That last line I don’t know anything about. I know it works for me, but if it doesn’t for you check your files in that same directory or /usr/share/ca-certificates or check out this page.

Now, since we are also using that gmail account to send mail from student@school.edu we put into .msmtprc

account school : personal
from student@school.edu

Essentially, that says inherit all defaults form the account personal but change the from field to student@school.edu

It should be easy enough to figure out the rest of your .msmtprc file.

Setting up Mutt

By default, mutt will look for $HOME/.muttrc or $HOME/.mutt/muttrc files. I like to use the latter because I have a few other mutt files that I’d like to keep together. Ok, let’s see what we need to put in our muttrc file.

First, we’ll need to specify the type of mail system we are using. As we set up with offlineIMAP we use Maildir

set mbox_type=Maildir

Now we need to say where we keep the mail:

set folder=$HOME/.mail

Now, it might make sense to visit that folder to see how our mail is stored. Inside $HOME/.mail, we should have two folders, net and personal. Inside each of those two folders there are all the gmail mailboxes with their own folders: INBOX,[Gmail].All Mail,…,personal (and any other labels that we may have). Each of these folders is a mailbox.

So now we want to specify where mutt should start when it opens up

set spoolfile=+"personal/[Gmail].All Mail"

I’ve written this relative to the folder specified earlier and I put it in quotes because it has some weird characters and a space.

Now, it’s called spoolfile because it’s supposed to be like a dumping ground where things will get moved from later. However, I let gmail do all my filtering and labeling so I don’t want anything to move be default:

set move=no

It is supposed to improve speed by making a cache of the headers:

set header_cache=$HOME/.mail/.hcache

Naturally, you can put this wherever you want.

Here’s a bunch of things that you’ll want to put in, they should all make sense:

set realname='Miggy Smith'
set from=personal@gmail.com
set sendmail="/usr/bin/msmtp"
set envelope_from=yes
set edit_headers=yes

I don’t edit my headers when I’m writing my emails, but I like to be able to see them. I like vim for writing my emails

set editor="vim +/^$"

This will launch vim with the cursor at the first blank line (so right after the header).

At this point, we should be good to go, but here are a few things that you shouldn’t have to live without.

Here’s what I think is the best sorting algorithm:

set sort=threads
set sort_aux=reverse-last-date-received

To look at mail in different folders, we can browse for the folders by using ‘c’ but we can do this better by setting up some mailboxes. We will get a list of them in mutt by pressing ‘y’ and mutt will say if they have new mail or not. To set up mailboxes, we just specify the folders in muttrc:

mailboxes +"personal/[Gmail].All Mail" +personal/personal +personal/school +net/INBOX

Obviously, set up whichever ones you want. (Okay so that looks weird above but those are just single spaces after each folder name…wordpress is trying to make it look pretty)

Lastly, if we are going to be in a certain folder/mailbox, we are likely going to want to send from a corresponding account.

We can set up commands like this in muttrc:

macro generic "1" ":set from=student@physics.school.edu"
macro generic "2" ":set from=personal@gmail.com"

So that if we type the escape key and then number 1 it will set the from field to student@physics.montana.edu. Then if you write a mail, it will use that as the from field.

But we can also do this automatically depending on what folder we are in:

folder-hook personal/personal set from=personal@gmail.com
folder-hook personal/physics set from=student@physics.school.edu
folder-hook personal/school set from=student@school.edu
folder-hook net/* set from=net@gmail.com

(Again wordpress is trying to make the above look pretty…those are just single spaces)

Further, when replying to emails, you’ll probably want to reply from the account they sent to you. Do this with reverse_name, but you’ll also have to tell mutt your default account and other accounts it may use:

set reverse_name=yes
set from=personal@gmail.com
alternates student@school.edu|student@physics.school.edu|net.gmail.com

All right. Enjoy gmail mutt and offlineIMAP.

Part 4 will be a few more tips and tricks when I get around to it.

How to set up Gmail Mutt and OfflineIMAP with multiple accounts part 2

May 3, 2009

This shall be an in depth look at how to set gmail with mutt and offlineimap using multiple gmail accounts.

This second part is how to set up offlineIMAP.

Part 1: Gmail
Part 2: offlineIMAP
Part 3: mutt

Why do you want to use offlineimap?

Check out offlineimap’s website. Essentially, you get the benefits of both pop and imap.

Offlineimap’s job is to download your email locally and make sure everything stays in sync. That is, if you make a change on gmail, it will be reflected automatically in the files on your computer. Likewise, if you move or delete an email on your home computer it will be propogated to gmail and therefore any other computer you may be monitering your email on. So, my emails are the same on my home computer and work computer without having to directly interface with gmail because offlineimap does that for me.

Setting up offlineIMAP

Here’s a great webpage for setting up offlineIMAP: full conf but I’ll go through the basic necessary configuration.

The default configuration file for offlineIMAP is $HOME/.offlineimaprc so create that file. I’m going to explain the things we need and put into code blocks the actual configuration that goes into that file. I’m only going to go through the necessary configuration to get this working well. There’s obviously a whole lot more configuration that’s available.

First, we need to set up the general information.


Now, let’s tell offlineimap we are using two accounts. We can call them whatever we want but it make sense to name them after our gmail accounts we are syncing with:

accounts = personal,net

Now, we need to lett offlineimap know it has to sync more than one account

maxsyncaccounts = 4

We only really needed to set this to 2 but it doesn’t hurt to make it 4 especially if we were to set up more accounts in the future and could forget to change this number.

Next, I want to tell offlineimap to go ahead and give up if it can’t get a connection within 60 seconds.

socktimeout = 60

Lastly, I can tell offlineimap what I want it’s interface to look like. From this site the choices are:

# Curses.Blinkenlights — A text-based (terminal) interface similar to Tk.Blinkenlights
# TTY.TTYUI — a text-based (terminal) interface
# Noninteractive.Basic — Noninteractive interface suitable for cronning
# Noninteractive.Quiet — Noninteractive interface, generates no output except for errors.
# Machine.MachineUI — Interactive interface suitable for machine parsing.

I think Curses.Blinkenlights looks good but it doesn’t let go of my terminal cleanly when it exits, so I’m using TTY.TTYUI.


You can easily override this choice with the command line option u. In running this periodically in a cron job, I’ll use something like offlineimap -u Noninteractive.Basic (do not put this in your config file!)

The general section is done, we now need to make the account information, one for each account.

[Account personal]

We can set up specifics such as how frequently to sync and whether or not to do quick syncs for full in this section, but I prefer to do just do that in a cron job, so all I’ll do here is create identifiers for the local (on this computer) and remote (on gmail) repositories.

localrepository = local-personal
remoterepository = remote-personal

local-personal and remote-personal are simply identifiers for a later section.

I’ll do something similar for my other account

[Account net]
localrepository = local-net
remoterepository = remote-net

Now I’ll say where my mail is to be saved on my computer. Also, I want to use the standard Maildir system.

[Repository local-personal]
type = Maildir
localfolders = /home/me/.mail/personal

[Repository local-net]
type = Maildir
localfolders = /home/me/.mail/net

Naturally, you can store your mail wherever you want. I like it in a hidden mail folder in my home directory. Before you can use offlineimap, these destination folders have to exist: mkdir -p ~/.mail/{personal,net}

Now, I’ll set up the interface with gmail. OfflineIMAP provides a custom Gmail type connection. I’ll use this. It’s possible that some of the information I have here is redundant using the gmail type but I haven’t experimented too much because it works no problem.

[Repository remote-personal]
type = Gmail
remotehost = imap.gmail.com
remoteuser = personal@gmail.com
remotepass = mypassword
ssl = yes
realdelete = no

[Repository remote-net]
type = Gmail
remotehost = imap.gmail.com
remoteuser = net@gmail.com
remotepass = mypassword2
ssl = yes
realdelete = no

Here, I’ve just straight up typed in my password into this file. I believe there are better ways to encrypt this information, but I guess I’m just not as paranoid as I should be.

I believe that realdelete = no is the default but it’s worth putting in there so that I can mention it.

Gmail puts your mail into your inbox and/or your labels but it also stores a copy in All Mail. If we were to delete a message on the local computer with this config, when offlineimap syncs, it will just strip the email of all labels and will leave the copy in All Mail. If we had set realdelete to yes, then offlineimap would even empty the email from All Mail and move it to the Trash folder. With the massive size of Gmail mailboxes, I don’t have the need to really delete things, so I set realdelete to no.

Okay, so let’s look at the whole file:

metadata = ~/.offlineimap
accounts = personal,net
maxxyncaccounts = 4
socktimeout = 60

[Account personal]
localrepository = local-personal
remoterepository = remote-personal

[Account net]
localrepository = local-net
remoterepository = remote-net

[Repository local-personal]
type = Maildir
localfolders = /home/me/.mail/personal

[Repository remote-personal]
type = Gmail
remotehost = imap.gmail.com
remoteuser = personal@gmail.com
remotepass = mypassword
ssl = yes
realdelete = no

[Repository local-net]
type = Maildir
localfolders = /home/me/.mail/net

[Repository remote-net]
type = Gmail
remotehost = imap.gmail.com
remoteuser = net@gmail.com
remotepass = mypassword2
ssl = yes
realdelete = no

Okay, let’s go ahead and sync for the first time. Depending on how much stuff you already have on gmail, this may take a while. Run the command offlineimap -o the -o says run once, which is probably what it would do anyway because I didn’t set any refreshing since I’ll let a cronjob do that.

If everything seemed to have went well, you can set up a cronjob. You can do this however you want, this is what I do: contrab -e to edit my crons with vi

*/10 * * * * * offlineimap -o -q -u Noninteractive.Basic
* */1 * * * * offlineimap -o -u Noninteractive.Basic

The first line does one quick update with the noninteractive interface every 10 minutes. The second line does a full update every hour. Full syncs will change the flags of emails, as in read/not read etc, where as quick syncs will only check for new/moved emails. I’m not sure it’s really worthwhile doing quick syncs over full syncs.

Okay that should be everything to get offlineIMAP working, next will be setting up mutt.

How to set up Gmail Mutt and OfflineIMAP with multiple accounts part 1

May 2, 2009

This shall be an in depth look at how to set gmail with mutt and offlineimap using multiple gmail accounts.

This first part is a statement of the problem and how to set up gmail.

Part 1: Gmail
Part 2: offlineIMAP
Part 3: mutt

The Scenario

I have three gmail accounts I want to work with. First is my school account. My school recently set up gmail for all the students which is where the official college correspondence goes. I also have an email account with my academic department. I am forwarding this email to my schools gmail account. They use an alias rather than the typical username@gmail.com it looks like student@school.edu; so let’s refer to this account as student@school.edu.

At the moment, POP and IMAP do not work with this account and I want to use mutt to work with my email so I forward everything to another gmail account where I also receive personal email. Let’s call this account personal@gmail.com

Lastly, I have a third account which I use for internet things. As in, I use this account when I sign up for a forum or use online stores or sign up for wordpress :) and that sort of thing. Let’s call this account net@gmail.com

Setting up GMail

Since I’m going to be receiving my school email at my personal account, I will prepare my personal account to receive this email cleanly. Logging in to my personal@gmail.com account I’ll go to settings then labels and make a new label called school. I want everything going to my school account to have this label. In mutt, these labels will show up as independant folders or mailboxes. So with my school label created, in settings I now select filters and make a new filter. I want anything going to student@school.edu to go to my school label so I type in that email in the “To” field click next and apply label: school. Since my departmental email is addressed to something like student@physics.school.edu I’ll apply a similar filter to also go to school or maybe a new phyiscs label. If you want all your email to stay in one pile, then you should just ignore the above instructions and everything will stay together in the inbox.

Now, I’m ready to send my student@school.edu email to personal@gmail.com

In my student@school.edu account, I go to settings then Forwarding/POP/IMAP. Here, I select forward a copy to personal@gmail.com and keep gmail’s copy in the inbox, as gmail says: so much storage, never delete another email again.

Now, I’m going to go back to my personal@gmail.com and set up the ability to send from different addresses. Specifically, since mail from 3 different accounts will be arriving in personal@gmaill.com, I want to be able to send and reply using each of them. In personal@gmail.com, under settings->accounts I’ll add an email address that I own. I’ll type in student@school.edu and send the verification email. Now, I’ll be able to check to make sure that the email is forwarded correctly and the label is applied correctly. I’ll do this for my student@physics.school.edu account as well.

My net@gmail.com account doesn’t require any special work. Obviously, you can make labels as you see fit.

Though I think it may be enabled by default, the last thing that needs to be done is to enable IMAP under my accounts: personal@gmail.com and net@gmail.com. Since I’ve forwarded all my school mail to personal I don’t need to enable IMAP under that account. To turn on IMAP I go to settings Forwarding/POP/IMAP and select enable IMAP

Next post will be on how to set up offlineIMAP