Operating System - HP-UX
1823914 Members
3249 Online
109667 Solutions
New Discussion юеВ

Re: Bold text on PS1 prompt?

 
Jay Crawford_1
New Member

Bold text on PS1 prompt?

My question is two part regarding .profile:

We have 50 machines but no standard profile. The potential to become confused on where you are is there, and I wouldn't want to reboot the wrong box!!! (not likely but still) I am creating a standard profile and have the following two questions:

1) Is there a switch or sintax that can be added to the PS1 variable, (defined in .profile) so to create bold text within the command line prompt? I have inserted the following line in .profile...

export PS1=`whoami`@`B.``hostname`:'$PWD>
#'

Which creates the following prompt:

root@systemname:/>
# _

...That way the admin always knows what user they are presently using, what system name they are on and what directory they are in. For directory trees and command strings which are long, I have dropped root's "#" prompt to the next line.

I still want to make very SURE an admin knows what system they are on ...so I'd like to display the hostname in bold text. (Man entries can be created using a ".B" switch, but this doesn't work here). Any ideas? examples?

2) I'd also like to trap separate history files for each session. We presently use the same history file each time. separate would be easier to track issues, and keep track of your commands.

Last item, (sorry for lenght!) Is there a best practices white paper on this kind of thing.

Thanks!
8 REPLIES 8
Paul Sperry
Honored Contributor

Re: Bold text on PS1 prompt?

PS1='${BOLD}`whoami`@`B.``hostname`:'$PWD>

For the bold part of the question
Sanjay_6
Honored Contributor

Re: Bold text on PS1 prompt?

Hi,

you can try,

export PS1=`tput bold``uname -n`:$LOGNAME:'$PWD">"'`tput sgr0`

Hope this helps.

regds
Jeff_Traigle
Honored Contributor

Re: Bold text on PS1 prompt?

As for the separate history file for each session, probably the best way is to append the timestamp to the history file name. Maybe something like:

HISTFILE=${HOME}/.ssh_history.$(date +%m%d%Y%H%M%S)
--
Jeff Traigle
Jay Crawford_1
New Member

Re: Bold text on PS1 prompt?


On PS1 syntax I'm not quite there yet...

${HOME:-.}/.profile[31]: syntax error: `;' unexpected

I'm expirimenting with my single and double quotes...
Jay Crawford_1
New Member

Re: Bold text on PS1 prompt?

Yep... Second option (for PS1) works great. Wasn't able to get the first one yet. Found the man on tput and discovered I can define the folowing...

b=`tput bold` #...then include ${b}just before the variable in question

These are your options...

b=`tput bold` #bold output
u=`tput smul` #underline
e=`tput rev` #reverse video
n=`tput sgr0` #normal output
k=`tput blink` #blink

or just use the tput variables themselves of course. Bold text comes out as reverse so it looks lame ...I did the following...

export PS1=`whoami`@`tput smul``hostname``tput sgr0`:'$PWD>

(you have to use sgr0 to turn off the text enhancement or it goes to the end of line.
Works like a champ! Still working the History point. Thanks guys!!
Sanjay_6
Honored Contributor

Re: Bold text on PS1 prompt?

Hi,

For the Shell history, you can try,

export HISTFILE=$HOME/.sh_history.`/usr/bin/tty`.`/usr/bin/date +%m%d%y%H%M%S`

Hope this helps.

regds
Bill Hassell
Honored Contributor

Re: Bold text on PS1 prompt?

Just a note about bold (and the many other tput video enhancements. The tput command is a Curses library interface that has it's roots in the Unix legacy of terminals. Back in the good old days (more than 20 years ago), there were dozens of terminals and manufacturers and not many agreed on the standards for character display. After all, the Unix console was originally a teletypewriter such as the ASR33 Teletype. A bold character was creating by printing a character, then backspacing and printing again, making the ink darker on the paper.

When the 'glass Teletype' became a reality around 1970, the concept of a hard-copy terminal required rework to match the paper effects that were in common usage. With only two colors (black and white/green/orange), something like bold had to emulated, usually with inverse video (dark letters on a light backgrounds). Underlining was also common, but glass tty's could also blink characters. And as the terminals became smarter, enhancements could be combined (bold + underline + blink). HP pioneered the smart terminal category with the 2640A and had the brightest characters (due to half-dot shifting), wide-screens (today = HDTV), and many video enhancements. The 2640A was the first implementation of the HP escape codes which would eventually become the base for the PCL printer language.

Other manufacturers, primarily DEC and Wyse, proceeded to develop their own terminal escape sequences with varied implementation techniques for the visual on the screen. The Curses library continued development to encompass all these features. To see the rich features available today, see the man pages for terminfo, tput, untic.

Almost no one uses terminals anymore. Instead, they are using PCs (which are not terminals) running some sort of terminal emulator. WRQ was one of the first companies to create a terminal emulator that could connect colors to various video enhancements. Later, other emulators would add colors and enhancements.

All this is background to why bold is not 'standard' across different emulators, and with emulator settings, can be different with the same emulator.

Another point of view about directories (especially Java): putting the entire directory path in the prompt can be really annoying. Usually, you need just the current directory and perhaps the parent (I like parent+current). I developed a customizable .profile snippet to handle the 3 most useful parts of a prompt: hostname, username and path. In the attached snippet, you can select one, two or all 3 fields and the enhancement to use for each field.



Bill Hassell, sysadmin
Arturo Galbiati
Esteemed Contributor

Re: Bold text on PS1 prompt?

Hi,

1.
if [[ [[ "$(tty)" = "not a tty" ]] ; then
B=''
R=''
else
B=$(tput bold)
R=$(tput sgr0)
fi
export PS1=${B}${LOGNAME}'$PWD'${R}

this because if you load the profile in not interactive mode (i.e. crontab) you will receive error if you use terminal command

2. To set different history files
HISTFILE=$HOME/.sh_history.$$

to remove it when exit to avoid fill directory
trap "rm $HISTFILE 1>/dev/null 2>&1" exit

HTH,
Art