rxvt/bash tab completion problem solved

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\O07\]\[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 (\O07)? (yes, that should read “007″, but wordpress filters out backslash-zero.)

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 with $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.

2 Responses to “rxvt/bash tab completion problem solved”

  1. Alpha Chen Says:

    Thanks for the tip; that was really getting to be a pain in the ass.

  2. the alpha newswire : Fixing tab completion in Cygwin Says:

    [...] It took me a little while to find out why Cygwin’s bash tab-completion wasn’t quite right, but MedWreck alerted me to the answer. Apparently bash incorrectly calculates the cursor position when tab-completing due to a complicated PROMPT environment variable. I trimmed it down a bit, and now tab-completion works the way it should. [...]

Leave a Reply