2

I have an alias jp for looking up Japanese words in the terminal via myougiden. Often I will be typing in Japanese in another application and will switch to bash to use the dictionary. However, when I have the Japanese keyboard turned on and try to input jp 言葉, OSX inputs jp 言葉, with full-width letters and spaces. This line then gets interpreted as a single command, which of course is not found. It is not convenient to switch back and forth between half-width romaji input, so I would rather bash interpreted the full-width input.

I can certainly add another alias for jp, but if bash can't interpret the full-width space then the command makes no sense. Is there any combination of aliases or settings that I can use to make bash interpret full-width spaces as regular half-width spaces?

  • I'm not familiar with this sort of problem, but can you just add the full-width space character to bash's IFS variable, which determines what separates fields. – meuh Jul 17 '17 at 19:39
  • That sounds promising! However, when I do IFS=" "; jp foo it tells me: -bash: jp foo: command not found. My $LANG is set to en_US.UTF-8. – Nate Glenn Jul 18 '17 at 9:56
  • You probably need to set IFS on a line of its own, and preserve its original settings IFS="<your space>$IFS". Is it possible to rewrite your jp as a simple shell script that reads one line from the input, then calls myougiden with that as parameter? It means 1 more <enter> to type. – meuh Jul 18 '17 at 12:20
  • I actually did set it on it's own line (I shortened it for the comment here). I could rewrite the script, but then the problem would come up again for other commands that take Japanese input. Maybe IFS doesn't allow general unicode characters? – Nate Glenn Jul 18 '17 at 16:08
  • You could try using the unicode code (U+3000 it seems for space): x=$(printf '\u3000'); IFS="$x$IFS". I tried b="echo$x/foo" after this and then $b got correctly executed as echo /foo. – meuh Jul 18 '17 at 18:01
2

A possible solution is to add a binding in your ~/.inputrc to replace the character by a space:

"\343\200\200": " "

You need to start a new bash shell to get the file reread. Or you type the equivalent command to the shell:

bind '"\343\200\200":" "'

The left-hand string is the utf-8 encoding of unicode u+3000 character which seems to be full-width space. If not you need to determine what the character code is your keyboard is generating.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.