Command Prompt Directory Styling

I have a particular need for adjusting the command prompt. At the moment i am using Holmans Dotfiles and I want to further customize it in order to create a prompt that’s more readable and clear. What I would like is described below using image, plz note that these are photoshopped in order to look as i want them to ;). This is also an issue on github, with inline images!

Let’s say you have this file structure as in this image:

  • How to find which actual command is executed in terminal
  • git update submodule via windows batch file
  • How to enter command with password for git pull?
  • launchctl git: command not found
  • Git Bash Open Command Windows
  • git -C command bug
  • enter image description here

    At the moment, when I am in lets say map3 my prompt only shows:


    I want to extend this but with alternative styling. At the moment the current map (map3) i am in is highlighted with cyan. I want to be able to see it’s parents but those not being highlighted in the same color. Plz look at the image below:


    from what i know, is that %3 gives the last 3 dir. However I don’t know how to style each dir individually.

    ————————— the other optional idea —————————————-

    The other idea I had, but which is of inferior importance to the problem described above is to have a relative prompt based on if a dir is a git repository yes or no. (so the dirtree is always visible up to the rootmap of the git repo)

    that is say that map0 is the root of the git repository and i am in map3, then I would like my prompt to be like this:


    when i am in map5 like this:


    optionally it would be nice to be able to style the rootgit map like this for example:


    at the moment my prompt is the same as in holmans dotfiles

  • dyld: unknown required load command 0x80000022 error with Git installation
  • Ansible: how to run task on other host inside one playbook?
  • Rejection when removing remote branch on git
  • git commit auto add new folders or files?
  • git: all local branches are behind the remote. How can I bring them all up to the remote state?
  • bash git pre-commit hook running MatLab function does not wait for a result
  • One Solution collect form web for “Command Prompt Directory Styling”

    Multi-color path in prompt

     directory_name() {
        CURRENT=`dirname ${PWD}`
        if [[ $CURRENT = / ]]; then
        elif [[ $PWD = $HOME ]]; then
            if [[ -d $(git rev-parse --show-toplevel 2>/dev/null) ]]; then
                # We're in a git repo.
                BASE=$(basename $(git rev-parse --show-toplevel))
                if [[ $PWD = $(git rev-parse --show-toplevel) ]]; then
                    # We're in the root.
                    # We're not in the root. Display the git repo root.
                    PATH_TO_CURRENT="${PWD#$(git rev-parse --show-toplevel)}"
                PROMPT_PATH=$(print -P %3~)
        echo "%{$fg_bold[cyan]%}${PROMPT_PATH}%{$reset_color%}%{$fg[red]%}%1~%{$reset_color%}"

    This’ll show the path to the git root (git root in magenta, unless you’re in the git root, in which case it’ll just show the current directory in red):

    Fixed some issues.

    Possible Improvements:

    1. This shows the root directory of the git repo in magenta, unless you’re in the root, in which case it’s red, like every other directory you’re in. Always-coloring a git root (even when it’s the current directory) might be nice (currently it may be confusing?).

    2. I show the path relative to the root of the git repo, if it exists. Another option may be to display the full path, coloring the root of the git repo, like the example below:

    3. Submodule coloring: Note in the screenshot that the path root gets reset to the deepest git repo (so when in a submodule, we don’t see config-files/oh-my-zsh, but only oh-my-zsh). I’m not sure how to detect submodules, but it could be a further improvement.

    Further Details:

    There’s a reasonably in-depth look [it’s my notes] of how I did all this here. It doesn’t yet have the final touch (path between git root and PWD), but everything else is there. It may be useful if you’re trying to modify this and want a better understanding.

    Git Baby is a git and github fan, let's start git clone.