Currently, I'm using the following:

export CLICOLOR=1
[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx

I have little clue on how this actually works! It does trim my directory to make it more readable, and adds some color.

enter image description here

Is there a way that I can modify my options here to make it super clear that I'm in a production directory? I'm thinking something like if my current pwd contains prod or production, then my prompt changes colors drastically (like annoyingly bright red, or some other obvious change).


Use the PROMPT_COMMAND setting, which allows you to run arbitrary code prior to printing the prompt. (Assumes bash.) As proof of concept:

PROMPT_COMMAND='case "$PWD" in *prod*) printf "\033[31m%s/\033[0m > " ${PWD##*/} ;; *) printf "%s/ > " ${PWD##*/};; esac'

Which uses an xterm escape code to set the foreground color to red if the PWD variable contains "prod" anywhere, but only displays the top most directory name in the prompt. Advanced color code discussion here: https://superuser.com/questions/270214/how-can-i-change-the-colors-of-my-xterm-using-ansi-escape-sequences

  • This kind of works, but it doesn't do what I'm looking for exactly (I'd rather not add more text to my prompt). – MrDuk Sep 13 '18 at 16:05
  • It's not set in stone. Modify it to your taste. PROMPT_COMMAND can be a simple or complex action. – Cupcake Protocol Sep 13 '18 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.