Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A useful multi-line command prompt UNIX
For those who use the terminal a lot, or use a UNIX machine at work a lot (like I do) here is a useful (at least to me) prompt that will allow easy viewing of what you type versus what the machines response is:
 alias setprompt 'set prompt="\\
`whoami`@`uname -n`: `pwd`\\
[\\!] "'
if ( $?prompt ) then # shell is interactive.
alias cd 'cd \!*; setprompt'
endif
cd
This provides a space on one line, the user id@machine: path on the second line and the command number (used for reference, such as !32) on the third line. All commands appear at the same distance from the left (commands 1 thru 99) (100-999) etc. That is what makes this usefull. I can always see what the last command was when I scroll back up.

You can leave out the uname -n part if you are on a single machine a lot (such as on your Mac) since this will "return" localhost and is not really useful for identifying your Mac. (You know you are alone and on 1 machine). In a multiple machine environment, this is handy to know which machine you are logged into. You can add other items in the if--endif to satisfy your needs (I have an alias for history set to h, for example). The reason you need the if--endif is so if you log in with a batch command, the prompt doesn't get set to confuse your commands in batch mode.

On a SUN UNIX box I have included spaces after the colon and after the final [\\!]. This allows selecting the path or command with the mouse (for copy/paste) easier for modification. (If your environment is set right, you can double-click on the path or command with the left mouse button and paste with the middle mouse button. This is great for repeat or simple modifing paths without knowing or using vi if your shell isn't bsh or tcsh)

Just so there is no confusion: the first quote is a regular quote, (middle row usually). The quotes around whoami, uname -n and pwd are back quotes and there is a double quote and single regular quote after the [\\!] . There are regular quotes around the cd \!*; setprompt in the if ... endif. The setprompt name is a user supplied name, you can use anything.
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[5,013 views]  

A useful multi-line command prompt | 4 comments | Create New Account
Click here to return to the 'A useful multi-line command prompt' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
printf: No match
Authored by: fm on Oct 02, '02 02:12:12PM
Cool tip!
But i get this error:
printf: No match
Every time I do a 'cd', e.g.:
[1] cd Desktop/
printf: No match.


[ Reply to This | # ]
Implementing Tip in bash
Authored by: cmccarthy on Oct 02, '02 03:58:44PM

If you're using bash instead of tcsh as your shell, the following line, entered as a command, has the same effect:

export PS1='\u@\H: \w\n[\!] '

Add this line to the .bashrc file in your home directory to have the prompt stay this way.



[ Reply to This | # ]
Implementing Tip in bash
Authored by: jldera on Oct 03, '02 08:45:00AM

This would work.... as long as you had a non-login session when you opened a shell in Terminal. If you've ever noticed though, the shells are a login session by default.. You have to either a) put that in .bash_profile or b) create a .bash_profile that contains the following:

. ~/.bashrc

I recommend (b) because you can work with just .bashrc for all shell sessions; without having to worry about which type of session you're changing.



[ Reply to This | # ]
More Prompt Information:
Authored by: wibbble on Oct 02, '02 05:20:50PM

A lot more information on setting interesting and useful prompts in BASH can be found in this HOWTO.

In particular, you can follow the guides there on displaying information in the titlebar of an Xterm and it'll work for setting the 'custom' part of a Terminal.app titlebar.



[ Reply to This | # ]