Left Over
Left Over

Reputation: 251

Is there any way I can change only a specific directory color in linux?

I only need to set a color that will only effect a particular directory not globally.

Upvotes: 0

Views: 1232

Answers (1)

Fred
Fred

Reputation: 6995

If you are using Bash in a terminal that supports colors and would like to change the default color for text output to the terminal (not specifically the output of ls) while inside this directory, there is one thing you could do.

The PROMPT_COMMAND variable can be set to execute a command just before printing the prompt. You could use that to check for the current directory and change the terminal color (for instance by assigning the PS1 variable with a prompt that contains non-displayable special codes for selecting a color or echoing said special codes).

PROMPT_COMMAND is documented in the Bash manual: https://www.gnu.org/software/bash/manual/bashref.html

As for how to assign colors, you should look that up if interested.

This solution may not be what you are looking for, will probably have side effects, and generally speaking, I am not sure it will be that useful changing terminal colors depending on the current directory. The usual solution is to have a prompt that shows the current directory path (or at least the last portion of the path).

I use something similar to the above to change text color depending on which machine I am executing Bash on, as I use ssh a lot from one machine to another over several terminal windows, and color (on a black background) is a good way to remember what machine any given window is connected to.

Upvotes: 1

Related Questions