Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

A guide to help set up Terminal Apps
Note that this guide assumes you're using the bash shell. This guide will address a few Terminal setup questions:
  • How do I get the backspace and forward delete keys to work correctly?
  • How do I get UTF–8 input to work correctly?
  • How do I get UTF–8 input to, you know, work correctly?
  • How do I get UTF–8 input to work correctly in irssi running under screen over a ssh connection?
  • How do I modify the default ANSI colors?
Read on for the answers to those questions...

How do I get the backspace and forward delete keys to work correctly?
  • In the Keyboard section of the Terminal Inspector (Command-I in Terminal):
    • Turn on the Delete key sends backspace option.
    • Map the forward delete key to the following string: \033[3~
  • Add the following line to your .profile: stty erase ^H. Since ^H is a non–printable control character, the easiest way to do this is to execute the following command: echo -e "stty erase ^H" >> ~/.profile. Type the ^H by pressing Control–V and Control–H.
  • Add the following line to your .inputrc: "\e[3~": delete-char
  • Apply changes by doing a source ~/.profile and a source ~/.inputrc.
How do I get UTF–8 input to work correctly?
  • In the Terminal Inspector:
    • In the Emulation section, turn off the Escape non-ASCII characters option.
    • In the Display section, choose Unicode (UTF-8) as the Character Set Encoding.
  • Add the following line to your .profile: export LC_CTYPE=en_US.UTF-8
  • Add the following lines to your .inputrc:
    set meta-flag on
    set input-meta on
    set output-meta on
    set convert-meta off
  • Apply changes by doing a source ~/.profile and a source ~/.inputrc.
How do I get UTF–8 input to, you know, work correctly?

There's an odd bug in the version of bash included with Mac OS X 10.4 that manifests itself as the LC_CTYPE enviroment variable not being set properly by export directives in .profile files. The workaround involves using the little–known environment.plist file. Thanks to Allan Odgaard for the tip!
  • Add a LC_CTYPE key with the value en_US.UTF-8 to the root dictionary of the ~/.MacOSX/environment.plist file. Assuming that you don't have that file, the easiest way to do this is to execute the following command:
    echo "{ LC_CTYPE = \"en_US.UTF-8\"; }" > ~/.MacOSX/environment.plist
    You could also use Property List Editor.app.
  • Apply changes by logging out and back in.
How do I get UTF–8 input to work correctly in irssi running under screen over a ssh connection?

You're a tricky one, aren't you?
  • Copy the relevant parts of your .profile and .inputrc to the remote host.
  • Start screen with the -U option.
  • In irssi 0.8.9 and older, set term_type to utf-8. In newer versions, set term_charset to utf-8.
After detaching, remember to reattach also using the -U option. This can be a bit tough if you're as used to typing screen -r as I am, so I suggest creating an alias. sru works well.

How do I modify the default ANSI colors?

Use Mike Solomon's TerminalColors utility.

An always up–to–date version of this guide can be found here: Setting up the Mac OS X 10.4 Terminal.app
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[37,447 views]  

A guide to help set up Terminal | 20 comments | Create New Account
Click here to return to the 'A guide to help set up Terminal' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
A guide to help set up Terminal
Authored by: Spartacus on Mon, Aug 28 2006 at 8:26AM PDT
I would love it if someone would post a similar hint for tcsh users. tcsh was the default shell in the first versions of Mac OS X and I have gotten used to it, especially with all the nice presets you can find in /usr/share/tcsh/examples/, but its way of stumbling on Unicode input drives me nuts.

Example:

1. type asédf
2. scroll to the beginning of the line with the left arrow key
3. scroll to the end of the line with the right arrow key
4. repeat 2 and 3 a couple of times
5. display is all messed up

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: weitzman on Mon, Aug 28 2006 at 9:40AM PDT
Huh? My Terminal has color management with full picker in Terminal => Window settings menu. Kinda hidden

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: gklinger on Mon, Aug 28 2006 at 10:04AM PDT
Yes, Terminal has a colour picker which lets you change the color of the cursor, selection, normal text, bold text and background. However, what if you want to change the default ANSI colors because, for instance, the blue is very dark and you can't see it well on your monitor? You're out of luck. That's where TerminalColors comes in. Install it and you'll see how it works.

[ Reply to This | # ]
Two Comments
Authored by: googoo on Mon, Aug 28 2006 at 9:42AM PDT
Thanks for the useful hint. I have two comments. (Perhaps I am missing something.) First, I noticed that Terminal.app maps the forward-delete key to \004 by default. If I add the following line to my .inputrc file, I get the expected forward-delete behavior.

"\004": forward-backward-delete-char

Just do not press the forward-delete key with no text in the command line. It logs you out (just like pressing ctrl-d).

The second comment is that I get error messages when I enter source ~/.inputrc because bash tries to associate thekeymappings with commands. Is there another way to reapply the .inputrc file?

-Mark



[ Reply to This | # ]
Two Comments
Authored by: mietek on Mon, Aug 28 2006 at 3:17PM PDT
Yes, just close the Terminal window and open a new one.

[ Reply to This | # ]
Two Comments
Authored by: googoo on Tue, Aug 29 2006 at 5:36AM PDT
What I meant was how do you re-read the .initrc file without exiting the shell?

-Mark

[ Reply to This | # ]
Correction
Authored by: googoo on Tue, Aug 29 2006 at 5:41AM PDT
I am sorry, but I should not try to type before having coffee. I meant, how do you re-read the .inputrc file without exiting the shell?

-Mark



[ Reply to This | # ]
Solution
Authored by: googoo on Tue, Aug 29 2006 at 5:50AM PDT
I found the answer by reading the bash man page (imagine that?). Use the following command.

bind -f ~/.inputrc

You can substitute another filename to read keymaps from that file.

-Mark



[ Reply to This | # ]
thanks plus a (worse) solution
Authored by: vike on Tue, Aug 4 2009 at 5:30PM PDT
ive read that manual a lot but you know, its oh so long and, many subjects are discussed at multiple occasions.
so thanks for that one i had missed.
it will probably come to replace my previous inputrc key-binding:
  control-r: re-read-init-file

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: gklinger on Mon, Aug 28 2006 at 10:25AM PDT
BTW, as long as people are setting up an .inputrc they might think about adding the following:

"\e[5C": forward-word
"\e[5D": backward-word

That will let them use ctrl + left or right cursor to move through words at the command line. I fiind it to be a big time saver. While I'm at it, the following is good too:

set completion-ignore-case On

It turns on case insensitivity for tab-completition (for example, hitting d + tab finds your Document directory).

Getting your shell setup 'just right' takes time but it's well worth it in the time it will end up saving you.

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: wpaulson on Mon, Aug 28 2006 at 2:19PM PDT
In the 10.3 Terminal.app, the "\033" in the keyboard pane isn't needed. That is, rather than "\033[3~" all that's needed is "[3~". I don't know if this differs from 10.4. behavior.

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: cyflea on Mon, Sep 4 2006 at 4:22AM PDT
why not configure screen properly while you're at it?

defutf8 on



[ Reply to This | # ]
A guide to help set up Terminal
Authored by: mietek on Wed, Sep 6 2006 at 2:33PM PDT
This isn't enough for Screen version 4.00.02 (FAU) 5-Dec-03, which is in debian-stable.

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: teras on Wed, Sep 6 2006 at 4:44PM PDT
When I use this hint, backspace in vi is not usable any more. Instead it produces a ^? character.
Any ideas about it?

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: teras on Wed, Sep 6 2006 at 5:13PM PDT
I found out that if I don't use stty erase ^H in .profile, backspace works fine in vi

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: sava on Mon, Nov 20 2006 at 3:00PM PST
Put in your vimrc
im ^? ^H
For ^? type backspace and for ^h type ctrl+h ctrl+v

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: sava on Mon, Nov 20 2006 at 3:01PM PST
I mean ctrl+v ctrl+h

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: Christoph on Thu, Sep 7 2006 at 6:27AM PDT
Does anyone know how the HOME and END keys (fn + ArrowLeft and fn + ArrowRight on iBook keyboards) can be enabled in Terminal?

This is one of the reasons why I still use xterm instead of Terminal.app.


[ Reply to This | # ]
A guide to help set up Terminal
Authored by: vocaro on Tue, Sep 19 2006 at 3:33PM PDT
Shift + fn + ArrowLeft and Shift + fn + ArrowRight

[ Reply to This | # ]
A guide to help set up Terminal
Authored by: sava on Mon, Nov 20 2006 at 1:14PM PST
..or in set in 'Keyboard' of Terminal inspector
end \033F[
home \033H[


[ Reply to This | # ]