Customise Shell Prompt

From Haiku Max Wiki

The BeOS Terminal is a bash/bourne sh type terminal and here is a guide to how to customize it into something cool besides the boring old defaults. I specify in this guide what works, and what doesnt in comparison to this article I am learning from: Enhancing Shell Prompts (http://www.pantz.org/scripting/shell/colorterm.shtml) Expected in your BeOS terminal is to set the font to 'Monospac821 BT Roman'. The bash version you should have is 2.03.0 . You can determine your bash version by pasting this code into your current open Terminal window. It is assumed that you have read, or have open the referred external link while you are reading this guide. This way you can compare whats going on, or why/where I wrote this or that! Trust me, the first time I looked at the colours and adding other special things, it looked like a big jumble. Here's something that helped me get through the learning process. I kept the 'Enhancing Shell Promts' page open and kept on experimenting and re-reading sections until I got the Terminal exactly as I wanted.

sh --version

The output should be exactly this. If it is not, the same results are not guaranteed as which this article states.

GNU bash, version 2.03.0(1)-release (i586-pc-beos)
Copyright 1998 Free Software Foundation, Inc. 
Table of contents

Before and After

Yuck, what an ugly image.
Yuck, what an ugly image.
Aha, that looks quite cool!
Aha, that looks quite cool!


Sequences that don't work

Sequence Description

\a  	The ASCII bell character (you can also type \007) 'this char doesnt actually show but is needed for the custom title bar for the terminal window' 
\e  	ASCII escape character (you can also type \033) 'this char doesnt actually show but is needed for the colours'
\l  	The name of the shell's terminal device (such as "ttyp4")
\j  	The number of processes you've suspended in this shell by hitting ^Z
\w  	Current working directory (such as "/home/drobbins") 'use $PWD instead'

Tweaking your shell promt

Basics

This is the command you're going to be using to modify your shell promt.

export PS1=""

You'd put some text inside the quotes.

Adding colour

Refer to Enhancing the System Prompt (bash) (http://www.pantz.org/scripting/shell/colorterm.shtml)

Changing the Terminal Welcome message

Open the file named 'profile' in /boot/beos/etc edit the text in between these '"\n \n"'

echo -e "\nWelcome to the BeOS shell, BeOS Mr X\n"

Save, and exit. Next time you open a Terminal the new settings are immediately noticed. If you grow tired of the welcome message the line in question can be removed and the welcome message will go away next time a terminal is loaded.

Saving your customised 'export PS1=' settings

Locate the file /boot/home/.profile or create it and insert the text you've used to customise your BeOS Terminal prompt. For example, the content of mine is:

export PS1='\[\e]2; \d , \@ | Welcome, to the BeOS Terminal\a\[\e[35;1m\]..::: \[\e[37;44m\]Be\[\e[37;41m\]OS\[\e[32;40m\] Mr. X\[\e[35;1m\] :::.. \[\e[37;40m\]$PWD\[\e[32;40m\] > \[\e[0m\]'

Changing the starting directory

For example, on the default settings when you load up a terminal, you are in /boot/home. I do not like this, since I have 6 other mounted drives/partitions and I don't usally save files or things to /boot/home . To edit the 'startup' location of your Terminal, navigate to this file: /boot/beos/etc/profile Notice how in the file, you can see:

#
# set the prompt and cd to the to our home directory
#
PS1='$ '
cd

Note: don't worry about the PS1='$ ' setting because our .profile file above we changed it so it's overidden. All I did was add a backslash / after the cd part and now the terminal opens where I want. Here it is, just for you

#
# set the prompt and cd to the to our home directory
#
PS1='$ '
cd /

Save, and exit the file. The changes are noticed immediately upon next launch of the Terminal.

Other ways to facilitate access to the Terminal

The Terminal is usefull if you frequently use apps like wget, and others. Here are the ways I access the Terminal quickly and efficiently:

Included with all BeOS versions, in the current foler hit win+alt+s

Right click on the ProcessController taskbar icon and choose New Terminal

  • Link made to the 'Terminal' on the top level directory of the Deskbar Menu:
ln -s /boot/apps/Terminal /boot/home/config/be/
  • I also use NaviTracker and hit the Terminal icon to load up a terminal. However, the profile and all the special options we can make aren't loaded like when we launch a BeOS Terminal.
Navi Tracker - Look at the Terminal Icon
Navi Tracker - Look at the Terminal Icon

To do/fix:

Before with each new terminal window, a number was added in succession to each new terminal opened. Now since I've edited the Terminal window title, this doesn't happen anymore. I haven't figured out how to add the feature yet.

Fixed: I couldn't make the $PWD work dynamically like I wanted. Everytime I changed a dir it wouldn't update or change. Looking at here http://www.betips.net/chunga.php?id=002 I noticed that my whole export PS1= was enclosed in double quotes instead of single quotes. Now that I have repaired to enclose my settings in single quotes, the $PWD displays new directories dynamically.

See Also