Install a new tcsh shell for better UTF8 support
Jun 13, '03 10:04:00AM
Contributed by: jpf
I was (until very recently) frustrated with the seeming inability of OS X to live up to part of its 'Unicode supporting' hype. That is, if you create files or folders whose pathnames contain multibyte characters (e.g., japanese) in the Finder, it's pretty difficult to actually do anything with them via the command line (i.e., in Terminal.app). Of course, you should see the names of the files displayed properly if you have the terminal window set to display utf8, but some other important functionality is sorely lacking for files and folders whose pathnames contain multibyte characters:
- Dragging an icon onto a Terminal window will show "garbage" for any multibyte characters in the file or folder's pathname, making this otherwise wonderful convenience useless (it's nice to be able to type "cd ", and then drag a folder's icon from the Finder and hit return, but it only works if the folder's path doesn't contain any multibyte characters).
- You can't directly access such a file or folder in the shell by just switching to the proper input method (e.g., via Command-space) and typing the pathname. This also means that it's pretty hard to create a directory or file with multibyte characters in its pathname interactively (in the shell).
- If you have a custom shell prompt that shows your current working directory, and you happen to be in a directory with multibyte characters in its pathname, your prompt will be messed up.
I fought with this in various ways and experimented with various non-solutions until I realized that there was probably a newer version of tcsh (the default shell for OS X) that might have utf8 support (the one that ships with 10.2 only seems to deal with euc & sjis). At that point, I had resigned myself to having to build my own tcsh, but when i went looking for the source, I ran across a binary version of 6.12.00 for OS X. Now, thanks to Kazufumi Tomori's efforts, we can all have decent utf8 support in Terminal.app without waiting for 10.3 or whenever Apple gets around to it.
Note that I certainly don't claim any credit whatsoever for his work. However, I thought that perhaps those unable to read Japanese, but who are nonetheless interested in a shell with utf8 support, might benefit from my rudimentary translation and paraphrasing of his installation instructions. The DMG file can be downloaded from his site by clicking the "DL / 0.6MB" button under "tcsh-6.12.00 for v10.2 Jaguar," and it contains two "package" files:
- tcsh-6.12.00-replace.pkg
- tcsh-6.12.00.pkg
Basically, the only difference in the two packages is that "tcsh-6.12.00-replace.pkg" will overwrite the stock tcsh in /bin/tcsh with the new version, while "tcsh-6.12.00.pkg" will place the new version in /usr/local/bin/tcsh instead. Note that if you already have a file /usr/local/bin/tcsh, it would be overwritten by installing the latter package.
There are a number of different ways one could choose to install either (you only need one) of these packages. The one described in Tomori's documentation suggests that, if you're installing the "replace" package, you make a backup copy of your original /bin/tcsh first. That's a good idea. He also notes that if you use the other package to install the new version into /usr/local/bin, you will need to edit /etc/shells to include the newly installed program in the list of "approved" shells before you can actually use it.
As this hint has already grown excessively verbose, I won't discuss here what /etc/shells is, or how to use sudo or whatever to edit it, nor how to change your default shell, etc. However, I will tell you the approach I took, which should work fine for most folks ... note that in the following, (root)% represents my shell prompt, and I am logged in (as you might suspect) as root. If you're not up for messing with root, you could likely just as well prefix the mv and ln commands below with sudo.
After installing "tcsh-6.12.00.pkg," open a Terminal window and type:
(root)% cd /bin
(root)% mv tcsh tcsh.6.10.00
(root)% ln -s /usr/local/bin/tcsh .
Don't forget that last dot! Now, if you do ls -l tc*, you should see something like:
lrwxr-xr-x 1 root wheel 19 Jun 10 17:02 tcsh -> /usr/local/bin/tcsh
-r-xr-xr-x 1 root wheel 315136 Apr 11 17:27 tcsh.6.10.00
One last step: cd back to your home directory and edit (as you, not root) your .cshrc or .tcshrc file to add the following line(s):
set dspmbyte = "utf8"
#the following is optional (see below)
set prompt = "%m(%n):%~%# "
Now, if you open a new terminal window and type set and hit return, you should see, among other things, a couple lines like the following:
dspmbyte utf8
version tcsh 6.12.00 (Astron) 2002-07-23 (powerpc-apple-darwin)
options 8b,nls [ ... ]
And you should now be able to do all kinds of utf8 stuff right from the shell, including using alternate input methods to create file and folder names in alternate scripts (admittedly, I haven't tried this for anything other than Japanese and some arbitrary 8-bit roman stuff and symbols, but it should work fine).
If you added the optional line to the .cshrc (or .tcshrc), your shell prompt will work right, too. I'd provide an example here, but since the macosxhints page ends up encoded as iso-8859-1, it wouldn't show up properly.
Finally, sorry about the length of this post; I tried to strike a balance between too much detail for experts, and not enough for newbies, but probably failed on both accounts.
Comments (16)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20030610125657969