Tuesday, December 05, 2006

Bash prompt customization

Using old UNIX machines is a pain sometimes. The 10-year-old features just don't mesh with the current ones, and it just doesn't feel right. Also, the prompt might not display any useful information. Heresy, I say! Follow these steps to make yourself feel more at home. Some information taken from this article.

To get an Ubuntu-like prompt (assuming bash is installed):
  1. Edit the .bashrc file with an editor like vi
  2. Add this as the last line: export PS1='\u@\h:\w$ '
Other prompt configuration options:
  • \! History number of current command
  • \# Command number of current command
  • \d Current date
  • \h Host name
  • \n Newline
  • \s Shell name
  • \t Current time
  • \u User name
  • \W Current working directory
  • \w Current working directory (full path)
To get easy access to some obscure directory: alias [name]="cd [absolute directory path]"

You can also edit the .login file, which executes immediately when you log in. (It might go by a different name depending on the shell... see here for details)

Use set -o emacs (the default) or set -o vi to set your command line editing mode of choice.

And remember kids, don't forget to write the other users if on a public machine! (Or maybe talk, or wall if you're the admin).

More links

No comments: