From 266ccc41407bc45d55987aee847201d4ca29dab2 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Wed, 22 Apr 2026 05:22:42 +0200 Subject: [PATCH] Highlight path in repo --- zsh/custom/themes/agnoster_dx.zsh-theme | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/zsh/custom/themes/agnoster_dx.zsh-theme b/zsh/custom/themes/agnoster_dx.zsh-theme index 05a814b..4d191e7 100644 --- a/zsh/custom/themes/agnoster_dx.zsh-theme +++ b/zsh/custom/themes/agnoster_dx.zsh-theme @@ -156,9 +156,32 @@ prompt_git() { fi } +git_toplevel() { + local repo_root=$(git rev-parse --show-toplevel) + if [[ $repo_root = '' ]]; then + # We are in a bare repo. Use git dir as root + repo_root=$(git rev-parse --git-dir) + if [[ $repo_root = '.' ]]; then + repo_root=$PWD + fi + fi + echo -n $repo_root +} + # Dir: current working directory prompt_dir() { - prompt_segment 12 $CURRENT_FG '%~' + if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then + # Git repo and inline path enabled, hence only show the git root + local repo_root=$(git_toplevel) + local path_in_repo=$(pwd | sed "s/^$(echo "$repo_root" | sed 's:/:\\/:g;s/\$/\\$/g')//;s:^/::;s:/$::;") + if [[ -z "$path_in_repo" ]]; then + prompt_segment 12 $CURRENT_FG "$(git_toplevel | sed "s:^$HOME:~:")" + else + prompt_segment 12 $CURRENT_FG "$(git_toplevel | sed "s:^$HOME:~:")/%B$path_in_repo%b" + fi + else + prompt_segment 12 $CURRENT_FG '%~' + fi } # Virtualenv: current working virtualenv