LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-24-2008, 09:24 AM   #1
ArcaneChaos
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Rep: Reputation: 0
Custom Command Prompt


Is it possible to customize the command prompt based on the current working directory? For instance, if I cd into a directory (or subdirectory within) I want my prompt to turn red. Is this possible in bash?
 
Old 07-24-2008, 09:37 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
It should be possible using the environment variable PROMPT_COMMAND: the content of this variable is executed as a regular Bash command just before Bash displays a prompt. You can find an example here. You can easily adapt the code to put a conditional statement which checks the current directory name and its parents.

Note: before changing the value of PROMPT_COMMAND, look at the current one. Usually it contains the command to set the dynamic title of the terminal windows.

Last edited by colucix; 07-24-2008 at 09:39 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
startx command in FC7 reverts me back to the command prompt sriram87 Linux - Newbie 5 01-03-2008 11:18 PM
getting custom PWD in bash prompt techrolla Linux - Software 2 08-09-2004 12:39 AM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM
can't make custom prompt work for root!? jaregi Linux - General 4 09-09-2003 11:40 PM
Custom boot prompt. drewskiamk Linux - General 1 06-22-2003 01:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration