lostwebsite.net blog

Annex to the Lost Website

Annoying non-breakable spaces in Bash/Zsh

with 2 comments

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 cd and $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. 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)

It took me a while but I’ve found that \302\240 is the Unicode sequence for non-breakable space. Once I have found that, I Google search lead me to Launchpad bug 218637.

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"
...

or use

setxkbmap -option "nbsp:none"

in a console, your favorite initialization file, or elsewhere.

About these ads

Written by fdgonthier

October 27, 2008 at 2:39 pm

Posted in Debian, Linux, Tips and Tricks, Ubuntu, X11

Tagged with , ,

2 Responses

Subscribe to comments with RSS.

  1. Non-breakable spaces created by AltGr+Space are only created when you use a terminal locale that uses the right alt/option key as AltGr, such as Canada (ca_enhanced) or something similar. Personnally, I use the US keyboard in shells (and Canada/ca_enhanced in other applications surch as mail, IM, etc.).

    I wonder if there’s a way of configuring the shell (or the terminal) to display an alternate character for the non-breakable space, something like

    Steven Pigeon

    October 30, 2008 at 4:04 pm

  2. Admiring the persistence you put into your blog and detailed information you present.
    It’s great to come across a blog every once in a while that isn’t the same old rehashed material.
    Fantastic read! I’ve saved your site and I’m adding your RSS feeds to my Google account.

    Natisha

    May 19, 2013 at 8:51 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: