Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Unix&Linux>>Customizing Terminal

Customizing Terminal

avalon
02-20-2006, 10:13 PM
With a lot of help I have been using Terminal to troubleshoot a problem. After reading the Terminal a lot I discover that it gets harder to read after you've been doing it a while. I'm a little dyslexic so I generally customize my Mac to minimize visual difficulities.

I just found and changed some Window Settings in Terminal. Most notably I made the font a little bigger and increased the ve3rtical spacing by about 10%. I changed the background color of the window. Stuff like that.

But what I would dearly love is the ability to make certain text stand out more. Is it possible to change the color of the whole command prompt? Such as:

Upstairs-Computer:~ robertkinleyjohnson$ ls -l /users/robe...

Is it possible to have input and out be different colors or font styles? And if non of that is possible, can you make Terminal change all carriage returns to 2 returns so that each commamd + command will look like one paragraph and each output would look likes its own paragraph. Though I guess you wouldn't want a list like the contents of a directory double spaced.... An indent for the first line could even help.

All or ANY of these alterations would make Terminal reading MUCH easier for me.

Thanks

hayne
02-20-2006, 11:22 PM
The prompt is something that is controlled by your shell, not the Terminal program. You can customize your prompt in Bash by setting the PS1, ... PS4 variables in your shell setup files. See this Unix FAQ (http://forums.macosxhints.com/showthread.php?t=40648) about the setup files and read the PROMPTING section of 'man bash'

Hal Itosis
02-21-2006, 02:40 AM
Is it possible to change the color of the whole command prompt?
I recently experimented with exactly that...
for example, putting:

export PS1='\e[32;45m\h:\w (\!) \$\e[0m '
in my .bash_login (similar to .profile). Problem was,
it made for some bizarre behavior. Like when using
the arrow keys to maneuver within the command line.
Text would start shifting around in strange ways.

There might be a righter way to do it, or maybe there
is something wrong with Terminal. (I've seen similar
complaints made by European users, with respect to
shifting chars when dealing with foreign encodings).

-HI-

PS - the 'Advanced Bash Scripting Guide' has a small
section devoted to colorizing (http://www.tldp.org/LDP/abs/html/colorizing.html). (note warning at bottom)

UncleJohn
02-21-2006, 06:36 AM
You can also embed newlines in your prompt string to help make the output more readable. For example, this will print a blank line, followed by the current working directory on its own line, then a simple "bash>" prompt.

PS1="\n[\w]\nbash> "

Results in this:

[/System/Library]
bash> uptime
7:31 up 6 days, 8:58, 1 user, load averages: 0.12 0.04 0.01

[/System/Library]
bash> echo 'hello world'
hello world

avalon
02-21-2006, 09:46 PM
Ahhh, John, so that's how you redefine PS1. And it's case sensitive.

I took the PS1 default value (``s-\v\$") and added a \r to the front. Laugh all you like. I thought it would add a return before the rest of the prompt.

Then to fix it I reset PS1 to that default value.

Upstairs-Computer:~ robertkinleyjohnson$ PS1=\r\s-\v\$
rs-v$
rs-v$PS1=``\s-\v\$"
>
>

Not quite what I had in mind, but at least not system damaging.

Two questions. How do I get back to Upstairs-Computer:~ robertkinleyjohnson$ being the prompt. And how do I add that return to the front of that prompt?

I haven't had a chance to read the color thing yet, Hal. But it's up soon on my array of tabs in the browser.

Thanks all

avalon
02-21-2006, 10:11 PM
Two questions. How do I get back to Upstairs-Computer:~ robertkinleyjohnson$ being the prompt

Okay, I got that one. I closed the window and opened a new one and the old prompt was there.

That begs though, is there anyway to make the changes I end up choosing stay permanant from window to window, session to session, restart to restart?

Adios

hayne
02-21-2006, 10:16 PM
That begs though, is there anyway to make the changes I end up choosing stay permanant from window to window, session to session, restart to restart?
I answered that in post #2.

avalon
02-21-2006, 10:58 PM
I answered that in post #2.

The prompt is something that is controlled by your shell, not the Terminal program. You can customize your prompt in Bash by setting the PS1, ... PS4 variables in your shell setup files. See this Unix FAQ about the setup files and read the PROMPTING section of 'man bash'

If you mean to say that the faq answers it, I wonder if you're referring to it referring you to the man bash. Specifically referring us to: The command number and the history number are usually different: the history number of a command is its position in the history list, which may include commands restored from the history file (see HISTORY below), while the command number is the position in the sequence of commands executed during the current shell session.


__________________

"What do you mean 'you are a halfling and are not a thief?' 3E, ah."

hayne
02-21-2006, 11:07 PM
If you mean to say that the faq answers it, I wonder if you're referring to it referring you to the man bash
No - I was referring to the fact that there is a section in that FAQ about the shell setup files.

tbsingleton73
03-01-2006, 06:08 PM
Avalon,

Were you able to do what you originally asked?
But what I would dearly love is the ability to make certain text stand out more. Is it possible to change the color of the whole command prompt? Such as:

Upstairs-Computer:~ robertkinleyjohnson$ ls -l /users/robe...

What command finally worked for you if you did get it to work?

trevor
03-02-2006, 04:57 PM
Here's some code for your bash configuration file that will help with colorizing text in your prompt:
# From http://homepage.mac.com/samchops/MACOSX/prelim.html
# Define some colors:
gray='\e[0;30m'
GRAY='\e[1;30m'
red='\e[0;31m'
RED='\e[1;31m'
green='\e[0;32m'
GREEN='\e[1;32m'
yellow='\e[0;33m'
YELLOW='\e[1;33m'
blue='\e[0;34m'
BLUE='\e[1;34m'
cyan='\e[0;36m'
CYAN='\e[1;36m'
violet='\e[0;35m'
VIOLET='\e[1;35m'
white='\e[0;37m'
WHITE='\e[1;37m'
NC='\e[0m' # No Color
# Now, include ${NC} in your PSx declaration to set the color to the default,
# or the color name such as ${gray} to a light gray and ${GRAY} to set the
# color to a dark gray. Feel free to set multiple colors in the same line of the prompt.

Trevor

Hal Itosis
03-02-2006, 05:30 PM
For now, this seems to be working:

PS1='\e[34;43m \h:\w (\!) \$\e[0m '

The first red part sets up blue text
on yellow background. (The 2nd one
turns it off). My 1st post has a link
that lists some color values, so you
can roll your own...

tbsingleton73
03-05-2006, 10:09 AM
I know the question was already asked above and the answer was to check the Unix FAQ, but I was not able to find the answer. I will ask again.

I want the following command to be applied permentlay to Terminal.app

export PS1='--------
\[\033[42m\]\[\033[1;34m\][\u@\[\033[1;34m\]\h]\[\033[42;1;31m\]==>> $PWD/..\[\033[00;1;32m\]\$ '

How do I do this. For now I have this saved to a text file and cut/paste when I want to use it in Terminal.

Thanks guys.

[credit]I have to give credit to stefaandk. The command above I got from his post in Unix - General. I have just modified to my liking.[credit]

hayne
03-05-2006, 10:24 AM
I know the question was already asked above and the answer was to check the Unix FAQ, but I was not able to find the answer.
Perhaps that was because you were looking for the question instead of the answer. To find the answer you need to read the whole of the FAQ. I.e. don't expect to be spoon fed - the answer is there but you need to spend some time in learning instead of just trying to fix your current problem.

As I said above, you should look in the section of the FAQ that discusses shell startup files and shell customization. You need to put the prompt-setup command into one of your "dot files".

tbsingleton73
03-05-2006, 11:50 AM
Thanks for not holding my hand, hanyne.

I was able to find the info. Opened .profile in Pico and saved it. Now it's there each time I open Terminal.

Learning Factor #4 (Exersice) shows it's value again.

Hal Itosis
03-06-2006, 01:39 PM
For now, this seems to be working:
PS1='\e[34;43m \h:\w (\!) \$\e[0m '

Eureka! YES...

Okay, the problem with the prompt colorizations I presented above is that:
if a very long command was in the history, and we used the up-arrow key
to step back thru the history... when we hit the long one, the display of it
on the command line would get jumbled up (as alluded to in my 1st post).

One solution is to enclose the color tags with 'non-printing' tags:

PS1='\[\e[30;47m\]\h:\W (\!) \$\[\e[0m\] '

I've switched there to black text (30) on a white span (47), because it looks
good with almost any color Terminal window. This works really well now.

Now that I look at it, that's the method tbsingleton73 used in his post...
but I didn't see it till now. (I found my fix studying the bashref manual).

-HI-

tbsingleton73
03-06-2006, 01:45 PM
While I would love to take credit, I just copied what stefaandk had from another post in a different forum. All I did was change the numbers to get the colors I wanted.


 

TOP

Windows Server Outsell
Unix Signals And C++ E

For more info

Unix Signals And C++ E
Windows Server Outsell
bash not using my .bas
Applescript: Hide Proc
help with installing p
Mozilla install from d
ssh - don't want to us
Escaping quotes in Tig
Terminal Keybindings 
JAVA help, please! 

News Archive

Displaying Images on t
Install Office from th
Terminal Problem...? 
cc1plus not executable
desktop icons.. 
at & growlnotify 
unknown terminal type 
scp arbitrary files 
What and why is a 'Dis
permissions already me

Related stories:

Installing Gnome and/or KDE
Startup causes Console in full screen mode
What goes in a .bashrc file?
My User folder was eaten by a platypus
Searching the "man bash"
su: Sorry?
large file copying broken in 10.4.5?

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics