PatrickMD.net

Thoughts on Medicine and Software

PatrickMD.net header image 2

rxvt/bash tab completion problem solved

October 11th, 2006 by Patrick

I love using Cygwin. I enjoy having the funky little command line utilities and a colorful bash shell window. It’s also funny when someone happens to peek over my shoulder and thinks I’m “hacking into something” just because I have an rxvt window open.

However, I had this nagging problem for the last few months or so that I finally looked into:

bash_completion_error1.png

This resulted in a long and eventually successful investigation into the dry world of rxvt/Cygwin relations.

The above is what happens when I type “ls f<TAB><TAB>”. The first tab fills out “oo/”, and the second <TAB> prints a list of possible completions. However, when it reprints the command line there is an extra “/” printed. This is really annoying, especially when you try to backspace, because the terminal’s and bash’s sense of line position are mismatched.

It turns out bash gets confused with the position calculation when complex prompts are used. I had this prompt:

export PS1=”\[33]0;\w\007\]\[33[032m\][\w]\[33[0m\]$ “

and to be honest, I can’t remember what the heck the first part is for. Something about ringing the bell (\007)? (yes, that should read “007″, but wordpress filters out backslash-zero.) (2008: Fixed with WP upgrade.)

I solved the extra slash problem by removing the first bracketed section:

export PS1=”\[33[032m\][\w]\[33[0m\]$ “

However, this still isn’t perfect, as I still get extra letters, as in this example where I typed “ls e<TAB>”:

bash_completion_error2.png

so I looked hard at the prompt line and decided that the “0″ in “032m” was superfluous, giving me:

export PS1=”\[33[32m\][\w]\[33[0m\]$ “

which passes both tests above:

bash_completion_error3.png
The moral of the story is to not use complex prompt strings.

I also found that I can set rxvt defaults in the $HOME/.Xdefaults file instead of a huge command line in a shortcut. So, this monster:

C:\cygwin\bin\rxvt.exe -ls -bg gray75 -rv -g 120×75 -fn “Lucida Console-11″ -sr -sl 10000 -tn rxvt -title rxvt-login -n rxvt-login –backspacekey \b -e /bin/ssh-agent /bin/bash –login -i

became:

rxvt*loginShell:        true
rxvt*background:        gray75
rxvt*reverseVideo:      true
rxvt*geometry:          120x75
rxvt*font:              "Lucida Console-11"
rxvt*scrollBar_right:   true
rxvt*saveLines:         10000
rxvt*termname:          rxvt
rxvt*title:             rxvt-login
rxvt*iconName:          rxvt-login
rxvt*backspacekey:      ^?

The full list of defaults is in the excellent rxvt man page.

Tags:   · · 2 Comments

Leave a Comment

2 responses so far ↓