Annoying non-breakable spaces in Bash/Zsh
This is an annoyance I found got around to solve. In Konsole, with a basic X configuration, when you type
AltGr Space, you get a non-breakable space. It might happen in other things X terminal/shell combo, or the both of them might not matter at all.
If you are an heavy shell user, you might hit the
AltGr Space combo by accident. This wouldn’t be bad if the shell made it somehow obvious that what you entered in a non-breakable space. The fact is that it doesn’t and it’s then totally impossible to distinguish a regular space with a non-breakable space after it was typed in the shell.
cd $HOME zsh: no such file or directory: cd /home/fdgonthier
After typing such a command quickly, I was often left wondering what the hell was wrong with my command, since, as far as I could see, it was syntaxically correct.
The problem is that since there is a non-breakable space between
$HOME, Zsh wants to execute the whole command as a single command. Since I didn’t know I could even type non-breakable space in X, I checked what the hell the shell was doing by using
strace is my favorite diagnosis tool for any kind of problems in Linux. Programs don’t lie when they are spied with
strace. The problem is obvious:
execve("cd\302\240/home/fdgonthier", ["cd\302\240/home/fdgonthier"], [/* 30 vars */]) = -1 ENOENT (No such file or directory)
On this page, you see that you can disable non-breakable space using a
xkb option in
xorg.conf. Simply add the following in the
InputDevice section related to your keyboard.
... Option "XkbOptions" "nbsp:none" ...
setxkbmap -option "nbsp:none"
in a console, your favorite initialization file, or elsewhere.