You are not logged in.
Pages: 1
The "Color Bash Prompt" Wiki page has no mention of Xresources but deals with configuring the prompt using .bashrc, /etc/bash.bashrc, and creation of /etc/DIR_COLORS.
As a newbie I have just installed the basic Arch and (with friendly forum help) have configured xterm using .Xresources, with a lot of colors provided. But in the process I did not come across anything in X Resources about the bash prompt color.
My question really is: does the use of X Resources supercede the Wiki page, and if so what would be the syntax for the entry?
Last edited by hilltownboy (2013-09-02 15:02:40)
Offline
What makes you think it should be possible to define prompt colour using X Resources? I've certainly never heard of that being possible. You define your prompt – including the colours it might use – by setting the PS1 environment variable, as the Wiki says.
Offline
No, that is not correct.
Here's how this works: A terminal emulator is a program whose task pretty much is to display the text that it receives from other programs, and to deliver user's input to these programs. When a program running “inside” a terminal emulator prints a string to its standard output (and assuming standard output is connected to the terminal), the terminal receives this string and takes care of rendering the letters on your screen. Your shell is just one of these programs running inside a terminal.
In addition to just dumb printing of strings, the strings may contain various escape sequences which the terminal interprets as commands instead of printing them on screen. One of these escape sequences is the “change foreground colour” escape sequence, usually rendered as “\e[00;3colourm”. So, e.g., the following command produces a colourful output thanks to these escape sequences:
$ echo -e '\e[00;31mfoo\e[00;36mbar'
foobar
An important point to realise here is that the echo command does not concern itself with colours at all – it merely received a string that its supposed to echo to the standard output; the string just so happens to contain some escape sequences. When echo delivers this string to the standard output, the terminal emulator picks it up, and starts reading it – it first notices the first escape sequence, “\e[00;31m” which in the arcane language of ANSI escape codes stands for “change the foreground colour to 1” – and so it starts rendering the subsequent text in colour 1. Then it comes across the string “foo” – that's not an escape sequence, so it's just rendered on the screen using the current foreground colour. In a simillar manner, the string bar is rendered in colour 6.
But wait a minute, 1 and 6 are not colours, they are numbers. Yes, but these numbers denote colours – the terminal emulator has an internal table which says that colour number 1 is red and colour number 6 is cyan. Here is where X Resources kick in – you can fine tune this internal table to your likings. E.g., if your .Xresources contains the line “URxvt.color1: #B21818”, then instead of using pure red (#FF0000) for colour 1, it'll be using #B21818, which is a bit toned down red that might look more aesthetically pleasing.
In this cooperation of terminal and programs connected to its standard input and output, the shell is nothing special: From the terminal's point of view, it is just another old program running inside the terminal. So if you instruct your shell to use the string "\e[00;31m\W $" as the prompt, what exactly happens when the shell decides to print the prompt is the following: The shell takes the prompt string, and looks for its own escape sequences in it. The shell does not understand the \e[00;31m sequence at all, but it does understand the \W sequence, so it replaces \W with the name of the current directory. After that is done, the shell sends the expanded string – “\e[00;31myour_working_directory $” to the terminal. The terminal does understand the ANSI escape sequence at the beginning, so it knows it's supposed to render the whole prompt in colour 1. It examines its internal table to learn what colour number 1 exactly means, and then proceeds to render the text “your_working_directory $” on the screen using the apropriate colour.
Hope this clears up some confusion about colourful terminals.
Last edited by Oxyd (2013-08-31 18:27:43)
Offline
Oxyd, thanks for your truly valid and understandable explanation. I will mark this post "Solved" after I am successful in coloring the bash prompt.
Offline
With the knowledge imparted above,I defined colors in .Xresources and was able to make the root prompt light red (rgb:FF/33/CC} on a dark green background (rgb:00/64/00). To make the red root prompt effective I placed the appropriate PS1 command in /root/.bashrc. There was no /root/.bashrc file so one had to be copied into /root/ from /etc/skel/.
The PS1 command used:
PS1='\[\e[31m\]\h: \w#\[\e[m\]'
Thanks for the help.
Offline
Pages: 1