Powerlevel10k: Feature Request: Truncate to Git Root

Created on 8 Oct 2019  路  3Comments  路  Source: romkatv/powerlevel10k

I was trying out different shorten strategies for my prompt and thought it would be really useful if anytime I went into a git repo my prompt would shorten to show the git root as the first anchor directory. For example:

~/Documents/projects/git_project/src/api

Would change to

git_project/src/api

Right now I have it set back on truncate_to_unique, but I imagine a case could be created using the list of non-shortened anchor dirs called truncate_to_last_anchor or something along those lines.

Most helpful comment

Try adding this to your ~/.zshrc.

function zsh_directory_name() {
  emulate -L zsh
  [[ $1 == d ]] || return
  while [[ $2 != / ]]; do
    if [[ -e $2/.git ]]; then
      typeset -ga reply=(${2:t} $#2)
      return
    fi
    2=${2:h}
  done
  return 1
}

Is it good enough?

All 3 comments

Try adding this to your ~/.zshrc.

function zsh_directory_name() {
  emulate -L zsh
  [[ $1 == d ]] || return
  while [[ $2 != / ]]; do
    if [[ -e $2/.git ]]; then
      typeset -ga reply=(${2:t} $#2)
      return
    fi
    2=${2:h}
  done
  return 1
}

Is it good enough?

Yes! this is great. Thank you.

Yes! this is great. Thank you.

You are most welcome.

By the way, this isn't p10k-specific. It'll work even with a simple prompt like `PROMPT='%~%# '.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mystic8b picture Mystic8b  路  4Comments

rpathak38 picture rpathak38  路  4Comments

ImKifu picture ImKifu  路  3Comments

lucascosti picture lucascosti  路  5Comments

maximbaz picture maximbaz  路  7Comments