Archive for November, 2007
Mercurial shell prompt, followup
I have already found a solution for the problem I stated in my last post. I was able to make a shorty Python script that get the information out of the Mercurial repository using Mercurial classes.
It was more simple than I expected. If I manage to clean that up, it would probably be an useful Mercurial extension.
I only paste the Python code here. I would like to setup a git repository for my $HOME/bin scripts. This is definitely not the final product, but it’s already something you can use.
#!/usr/bin/python
import mercurial
import sys
from mercurial import ui, hg;
myui = ui.ui()
try:
# Instanciate the repository.
hg_repo = hg.repository(myui, sys.argv[1])
# Get some informations.
hg_branch = hg_repo.dirstate.branch()
hg_rev = hg_repo.changelog.rev(hg_repo.changelog.tip())
if hg_repo.dirstate._dirty:
hg_dirty = "1"
else:
hg_dirty = ""
print "hg_rev=%s\nhg_branch=%s\nhg_dirty=%s" % (hg_rev, hg_branch, hg_dirty)
except Exception, ex:
sys.exit(1)
Mercurial shell prompt
I thought this could be interesting.
Based on this post by Mike Hommey, I decided to setup my own Mercurial-aware ZSH prompt.
Here the revelant part of my .zshrc.
function precmd {
psvar=()
if [ ! -e `pwd`/.hg ]; then
PROMPT=$DEFAULT_PROMPT
return
else
# TODO: We need some way to know quickly if there are changes.
hg_tip=`hg tip --template 'hg_rev={rev};\nhg_branch={branches}'`
hg_status=`hg status -mardi`
eval $hg_tip
psvar[1]=$hg_rev
if [[ "$hg_branch" == "" ]]; then
psvar[2]=default
else
psvar[2]=$hg_branch
fi
if [[ "$hg_status" != "" ]]; then
psvar[3]="*"
else
psvar[3]="-"
fi
PROMPT="[r:%1v b:%2v s:%3v]%n@%m:%1d > "
fi
}
export DEFAULT_PROMPT="%n@%m:%~/ > "
export PROMPT=$DEFAULT_PROMPT
See the TODO for the problem I currently have with that. It is calling Mercurial twice. Mercurial is fast, but its still not a native program and it takes a noticable time to update the prompt. If I got all the informations in one call to hg I would be quite happy, but I feel I would need to hack some Python code and use the Mercurial classes.
The resulting prompt is compact and quite nice:
[r:4 b:debian s:-]fdgonthier@moka:spamassassin >
Little Gamers book IV
Book 4 is soon ready for pre-orders, and the guyz still have special gifts for the early pre-orderers, which I will again try to be on December 1st.
The Little Gamers don’t puch much effort into creating new content for the book, but it’s much more fun to handle a paper book than to go through the archive.
It’s the webcomic that I have had the most fun to read, re-read and re-re-read in book form.
I’m not gonna try to sell the Little Gamers to anybody here. Just remember that before going to http://www.little-gamers.com that their comic doesn’t have much to do with gaming (despite some occasional gaming reference), and that the art style, is, mmm, minimalistic to say the least.
Here is a sample. Click the link above for the link to the site since I don’t yet know how to do a image-link with Markdown

Shell Trick
I love shell one lines. I love how twisted they look and how they can do complex task quickly, even if it takes me 30 minutes to find the right way. Sometimes, even when I end up with a result, I’m not satisfied.
I hereby share a twisted bit of code which lists in order of priority all the packages in the debian-installer section.
So, Interweb, Is there any way to improve that?
cat Packages | grep-dctrl -FInstaller-Menu-Item -e ".+" -sInstaller-Menu-Item,Package -n | for i in `cat`; do if [ -z "$z" ]; then echo -n $i; z=1; else echo " $i"; unset z; fi; done | sort -n
Not that I expect any readers for now.
longlines-mode
Thank you Tom Westphall. Emacs longlines-mode is indeed very useful!
A blag, I has it
Hello,
Yeah I got a blag. Nobody will care that it’s about the third or fourth time I try to commit myself to blogging. I have not found any good reasons not to blog yet. I got knowledge and opinions to share.
I will try to make this blog not too self-centered. I feel it will be easier for me to blog about what I know than about what I am. I don’t want this to be a diary read by the whole Internet. I think I might have grown past the age of diaries anyway.
But, diary aside, I would like whoever reads this to know who they are reading about. I’m a 27 years old computer programmer from Sherbrooke, Québec, Canada. I work at Kryptiva, a young email-centric innovation company. I will not blog much about work. Most of the things I have programmed at Kryptiva are proprietary, an I can’t say much about it. I don’t feel its of the greatest interest anyway. On other hand, we do work in a fully open-source environment, and I get to do nice things with open-source tools. There is certainly room for future posts there.
I have a 6 weeks old daughter too. As I said, I will not blog about personnal matters (not much), but as it is quite new in my life, I feel I could have quite a bit to say. Another problem with blogging about Charlotte is I feel the site itself might be a bit too dry for what I have to say and for the people that will read it.
That’s it for now. I will get into what I do at work and at home, related to open-source tools and Linux, in my next post.
Ubuntu on Sid
Did you know you could pretty much install Ubuntu on Debian Sid? Now you do!
Well, yes and no.
Yes because I installed a set of Ubuntu packages on a (de)bootstrapped Sid Debian distribution.
No because the debootstrap actually installed Ubuntu packages, and the set of packages Ubuntu and Debian install at their base are actually quite similar.
If you diff the 2 debootstraps scripts (Ubuntu Gutsy vs. Debian Sid), you’ll see very little difference between the 2. To make that work you have to alias the Debian Sid distribution to Gutsy otherwise deboostrap will fail saying it can’t find the source distribution on the mirror.
On the CD I’m making, I’m using a custom distribution name, made off Ubuntu packages. With a quick hack to deboostrap, you can make debootstrap install Sid using Gutsy packages!
