How to change prompt color when changing path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to change prompt color when changing path
# 1  
Old 07-21-2008
How to change prompt color when changing path

Hi all,

Can you tell me how to change the prompt color (only the path part) when I chnange directory with "cd"?

I use the sequence below in ".bashrc" (Solaris 8) to change my prompt colors and I'd like to modify it to change the path color when I cange directory.

Code:
PSC() { echo -ne "\[\033[${1:-0;34}m\]"; }
function PWD() { echo "$*" |perl -pne \
  's:^'"$HOME"':~:;s:^(.{8}).{4}.*(.{20})$:$1...$2:;'
}
PR="0;34"        # this is blue
PSbase="$(PSC $sudo)\u$(PSC $PR)@\h $(PSC 33)\$(PWD \w)"
PS1[1]="$PSbase$(PSC $PR)\$ $(PSC)\e[0m"
PS1="${PS1[1]}"
unset sudo PR PSbase

The results are(the text colored in black is actually white):
root@localhost ~/dir1/d..._dir/really_long_dir$ pwd
/root/dir1/ddd/aaaaaaaaaaaaaaaaaaaaaaa/verry_long_dir/really_long_dir
root@localhost ~/dir1/d..._dir/really_long_dir$

The desired result is:
root@localhost ~/dir1/d..._dir/really_long_dir$ cd new_dir/
root@localhost ~/dir1/d...lly_long_dir/new_dir$

And if I change again the directory it should turn back to green.

Any ideea how to do this?

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

2. UNIX for Dummies Questions & Answers

How to Change the % prompt to - prompt in UNIX?

how to Change the % prompt to - prompt in unix :wall: ---------- Post updated at 07:40 AM ---------- Previous update was at 07:38 AM ---------- How To display the last modification time of any file in unix ---------- Post updated at 07:40 AM ---------- Previous update was at 07:40 AM... (2 Replies)
Discussion started by: manjiri sawant
2 Replies

3. Shell Programming and Scripting

Color prompt with file numbers does not work anymore

I have used this color prompt on my servers for long time, in file ~\.bashrc Black="\" Dark="\" Blue="\" LBlue="\" Green="\" LGreen="\" Cyan="\" LCyan="\" Red="\" LRed="\" Purple="\" LPurple="\" Brown="\" Yellow="\" LGray="\" White="\" Reset="\" PS1="$Yellow\u@\h $LBlue\w... (4 Replies)
Discussion started by: Jotne
4 Replies

4. UNIX for Dummies Questions & Answers

How to change the background color in the init 3 mode(not line color)

Hello, I am using RHEL 6.1 on VMware I am searching for a way to change background color (not line by line color wich one can using tput command) basically changing the color of the whole screen to white instead of the default black and changing font color to black and alos would like to... (2 Replies)
Discussion started by: Dexobox
2 Replies

5. Shell Programming and Scripting

zsh, prompt, variable expansion, ANSI color sequences

Hi! I am using latest ZSH and I have setopt prompt_subst I have a global hash array variable which contains some color definitions with color names as keys and 256-color ANSI codes (with %{ and %}) as values, eg %{\ePS1="$FG Hello World (%M) > " or PS1=$'$FG Hello World (%M) > ' then it... (3 Replies)
Discussion started by: galanom
3 Replies

6. Shell Programming and Scripting

Bash - changing a color of a substring

Hello! I need to write a bash script for my university classes, and I came up with an idea of a program that would test the speed of typing - there is some random text that you have to rewrite, and the script measures time, number of mistakes etc. The text would be visible on the screen all... (3 Replies)
Discussion started by: xqwzts
3 Replies

7. Shell Programming and Scripting

tcsh/csh: set prompt in production to color red

Hi folks This is our prompt at the moment oracle@pinkipinki:/opt/oracle> grep 'set prompt' .cshrc set prompt = "$user@`uname -n`:$cwd> " We wish to have in production the same prompt, but red. Howto do that? I tried a lot a internet manuals, but it doesn't work. (1 Reply)
Discussion started by: slashdotweenie
1 Replies

8. Programming

changing text color in c

I'm writing my own Unix ls command in c and I was wondering if anyone knows how to or can point me to a tutorial that shows me how to change the text color of the filename depending on if it's a directory, regular file, linked file, etc..., like the real ls command does? Thanks. (4 Replies)
Discussion started by: snag49ers
4 Replies

9. Shell Programming and Scripting

Executing Commands From Non-Standard Path (Changing user's PATH secretely???)

Hi: I have a requirement as below: I have some standard Unix commands modified and kept them in a directory say /usr/clsh/bin. For example I have a script named "ls" kept here which is modified version of "ls" (say it always gives long listing i.e. ls -l). When any user logs on and types... (2 Replies)
Discussion started by: ramesh_samane
2 Replies

10. UNIX for Advanced & Expert Users

Changing Text Color Using VT100

Hi, I want to change the color of the text. Currently, I am using the following VT100 command, which changes the color of the foreground: <ESC>[{attr1};...;{attrn}m The problem is, when I change the color of the foreground, it changes the color of the text as expected, but it also... (4 Replies)
Discussion started by: Abed Alnaif
4 Replies
Login or Register to Ask a Question