Tuesday, October 16, 2007

MacOSX + Linux + stty + terminfo + X11 + xterm + screen = backspace is teh suck

I got the backspace key to work across machines and with various programs, but it wasn't easy. Every keystroke goes through a ton of different layers that can remap keys in arbitrary and usually broken ways:
  • MacOS keyboard maps
  • X11 xmodmap
  • xterm VT100 widget X resources (from .Xresources through xrdb)
  • ssh
  • Linux kernel terminal driver (through stty)
  • terminfo (chosen via the $TERM environment variable, used by libraries such as curses)
  • GNU screen (the "bindkey" command in .screenrc)
  • the actual application:
    • shell keymaps (the "bindkey" builtin command in zsh, configured via .zshrc)
    • emacs keymaps (some .el file)
Here's the various settings I changed to get this working consistently:
In X11.app's X11 Preferences, "Use the system keyboard layout" is checked, "Enable keyboard shortcuts under X11" is unchecked.
In ~/.Xresources on my MacBook:
*locale: UTF-8
XTerm*metaSendsEscape: true
XTerm*backarrowKey: false
XTerm*backarrowKeyIsErase: false
XTerm*termName: xterm-color
In ~/.zshrc:
bindkey "^?" backward-delete-char
Changed some settings in ~/.terminfo/x/xterm-color in Linux to match the mac's xterm resources:
bce@, # mac's xterm is too old to support back color erase
kbs=\177, # backarrow key sends ^?
kdch1=\E[3~, # forward delete key
Wasn't that easy?

Tuesday, October 9, 2007

How to get the Mac "Command" key to work as Meta in xterm

cp /private/etc/X11/xinit/xinitrc ~/.xinitrc

cat >~/.Xresources <<EOF
xterm*metaSendsEscape: true
xterm*saveLines: 10000
xterm*scrollBar: true
xterm*rightScrollBar: true
xterm*jumpScroll: true
EOF

xrdb -merge ~/.Xresources

Thursday, August 23, 2007

XTerm title setting in zsh

I always forget how to configure zsh to set the title of an XTerm automatically, and I usually just copy some code on the web without really understanding it. I finally tracked down how the stuff works behind the scenes and wrote an easier-to-understand version myself (loosely based on some random code found via Google of course):
set_xterm_text_params() {
local param=$1
shift
case $TERM in
xterm*|rxvt) print -Pn "%{\e]$param;$*\a%}"
esac
}

set_xterm_title() {
set_xterm_text_params 0 "$*"
}

set_xterm_icon_name() {
set_xterm_text_params 1 "$*"
}

set_xterm_window_title() {
set_xterm_text_params 2 "$*"
}

tag() {
if [[ $# -eq 0 ]] ; then
custom_tag=""
else
custom_tag="$*"
fi
}

# preexec() runs before each command. The command line used to run the
# program is $1. That allows this hack, which shows the name of
# whatever command is currently running, directly in the titlebar. The
# expansion parameter (V) makes any special characters in the string
# visible.

preexec() {
set_xterm_title "${custom_tag:+$custom_tag - }%n@%m: %50>...>${(V)1}%<<"
}

# ZSH runs precmd() before each prompt. Because of the above preexec
# hack, I use it to display the pwd in the titlebar. Most people use
# chpwd for this, which is a bit more efficient, but that obviously
# wouldn't work in this case.

precmd() {
set_xterm_title "${custom_tag:+$custom_tag - }%n@%m: %50<...<%~%<<"
}

Wednesday, August 22, 2007

Various bugs

  1. TRAMP and zsh don't get along. In particular, it appears that the PROMPT_SP zsh option (which outputs special characters to mark command output that doesn't end in a newline) causes the zsh prompt to no longer match the shell-prompt-pattern emacs variable, which is set to "^[^#$%>\n]*[#$%>] *" by default. I added the following hack to my .emacs file to fix the problem:
    (eval-after-load "tramp"
    '(setcdr (assoc 'tramp-login-args (assoc "sudo" tramp-methods))
    '((("-u" "%u") ("-p" "Password:" "/bin/sh"))))

  2. Connecting to some servers via ssh was taking way too long, around 10 seconds. Running "strace ssh -vvv" showed that the program was hanging while trying to do a reverse DNS lookup on the IP address of the server (i.e. getnameinfo). The culprits were the mDNS resolver (libnss-mdns) and Avahi daemon — they were broadcasting reverse mDNS lookup requests to the local network and timing out very slowly. The fix was easy: remove the "mdns" entry from the "hosts:" line in /etc/nsswitch.conf (I love Linux...).

Wednesday, July 25, 2007

Favorite Firefox extensions

Can't live without:
Adblock plus
Flashblock
Firebug
Greasemonkey

Still trying out:
Web Developer
Google Browser Sync
S3 Firefox Organizer

How I got my 4GB groove back

Intel Core 2 Duo
ASUS P5B-E motherboard (Intel 965p chipset)
4x1GB DIMMs
Some random nVIDIA graphics card
Ubuntu 7.04 "Feisty Fawn" i386 (32-bit)


  1. Install the Ubuntu "server" kernel, which supports PAE for up to 36-bit physical memory addressing:
    sudo apt-get install linux-image-server linux-headers-server
  2. The Linux kernel mistakes the 965p chipset for a 965g chipset with built-in graphics; when the BIOS has memory remapping enabled, the kernel dies while probing for Intel AGP support. Blacklist the Intel AGP module:
    sudo sh -c "echo blacklist intel_agp >> /etc/modprobe.d/blacklist"
  3. Download the (non-free) NVidia driver installer
  4. Reboot
  5. Bring up the BIOS setup screen: press Delete when the splash screen appears upon booting
  6. Enable "Advanced > Chipset > North Bridge Configuration > Memory Remap Feature", press F10 to save changes and reboot
  7. In the GRUB boot menu, choose "Ubuntu, kernel 2.6.20-16-server"
  8. Don't bother looking at the logs when the X server fails
  9. Log into the console, install/update the graphics driver and compile a new nVIDIA kernel module:
    sudo sh NVIDIA-Linux-x86-100.14.11-pkg1.run -a
  10. Restart the GNOME display manager to log in to X:
    sudo /etc/init.d/gdm restart
  11. Profit?