I'm using Finnish keyboard layout which maps AltGr+Space to non-breaking space (NBSP, U+00A0). I'm happy with this in general but I find that I often accidentally write NBSP instead of normal space after pipe "|
" symbol (written with AltGr+< with Finnish keyboard layout) while using bash command line. I guess this is caused by the fact that I need to hold AltGr while typing the pipe and release it before hitting space. And when I have bad timing for the release of AltGr I end up with invisible typo on the command line and error messages such as
grep: command not found
which looks pretty similar to
grep: command not found
which makes this issue a bit hard to notice on the first time.
I know that I can disable NBSP but I would prefer disabling it (having AltGr+Space to produce regular space) only after pipe character, or if that's not possible, always on the bash command line or readline
level. Is there any simple way to do this without modifying source code of bash, readline
or my terminal emulator (gnome-terminal
)?
Another good solution would be to configure NBSP to be somehow visible on the command line, e.g. replaced with another character (say U+2423 ␣
) for rendering only.
This can be done on the
readline
level two different ways.Method 1
Put following in
.inputrc
(the configuration file forreadline
):If markdown messes up the above, you have to put NBSP in quotes on the left side of colon as explained in the comment. This will map any occurrence of NBSP on input stream with a regular space.
Method 2
Put following in
.inputrc
:The idea is to map key sequence {pipe followed by NBSP} to {pipe followed by space}. This works if you type the sequence within 250 ms (configurable above). However, until the timeout is gone, typing pipe symbol alone will not output anything. And if you type the sequence too slow, the fix will not be applied. Also note that the timeout is global so if you intend to use any other sequences, you have to set timeout long enough to be able to type the longest sequence. (The readline library is not clever enough to allow typing the characters and later replace already visible characters after the character sequence matches the configuration.)
There's an excellent article dealing with this problem:
I've been attempting to address the primary concern with
grep
error messages and changing NBSP to something more visible usingexec
command. I haven't got the syntax down pat yet though:The idea is to have this command in
~/.bashrc
so it automatically loads withgnome-terminal
opening. But as I said it's not working yet...