Powerlevel9k / powerlevel9k

Powerlevel9k was a tool for building a beautiful and highly functional CLI, customized for you. P9k had a substantial impact on CLI UX, and its legacy is now continued by P10k.
https://github.com/romkatv/powerlevel10k
MIT License
13.47k stars 947 forks source link

is it possible to create a special directory color ? #1124

Open jerome-diver opened 5 years ago

jerome-diver commented 5 years ago

Hi and thank you for powerlevel9k, very nice prompt (i use it with zsh, it is perfect). I would like to create a special directory color. For example, i can define a POWERLEVEL9K_DIR_HOME_BACKGOUND color... In the same way, i would like to define a kind of POWERLEVEL9K_DIR_HTTP_BACKGROUND color for directories where user is "http" (for http user), but not the home directory of http user. Is it possible and how to do that please ?

ionsquare commented 5 years ago

Would a custom prompt segment work for you instead of modifying a core segment?

zsh_dir_owner(){
  owner=$(stat -c "%U" .)
  if [[ "$owner" == 'www-data' ]]; then
    echo $owner
  fi
}
POWERLEVEL9K_CUSTOM_DIR_OWNER="zsh_dir_owner"

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=($POWERLEVEL9K_LEFT_PROMPT_ELEMENTS custom_dir_owner)
POWERLEVEL9K_CUSTOM_DIR_OWNER_BACKGROUND=yellow
POWERLEVEL9K_CUSTOM_DIR_OWNER_FORGROUND=black

You could even change the check to something like this to show the segment if you're in a directory owned by anyone other than the current user:

  if [[ "$owner" != "$USER" ]]; then
    echo $owner
  fi