From 3c307e847924ea9513f3b1dacdbc5f6ea11d4f77 Mon Sep 17 00:00:00 2001 From: Kilobyte22 Date: Mon, 27 Jul 2015 23:26:49 +0200 Subject: [PATCH] Fixed an artifact from merge and some bugs in agnoster theme For some reason i forgot to save the file in my editor, leading to the code not working. Luckily i looked through the changed files on github again and i found this. This is what happens if you don't care to actually test your code for once Due to some more lack of testing i totall missed that my earlier fix did not work. This is now really fixed. (i should not write code when tired.) --- themes/agnoster.zsh-theme | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme index 8051ad265..d0208d592 100644 --- a/themes/agnoster.zsh-theme +++ b/themes/agnoster.zsh-theme @@ -127,6 +127,18 @@ prompt_end() { CURRENT_BG='' } +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 +} + ### Prompt components # Each component will draw itself, and hide itself if no information needs to be shown @@ -138,11 +150,7 @@ prompt_context() { } prompt_git_relative() { - 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) - fi + local repo_root=$(git_toplevel) local path_in_repo=$(pwd | sed "s/^$(echo "$repo_root" | sed 's:/:\\/:g;s/\$/\\$/g')//;s:^/::;s:/$::;") if [[ $path_in_repo != '' ]]; then prompt_segment "$AGNOSTER_DIR_BG" "$AGNOSTER_DIR_FG" "$path_in_repo" @@ -276,7 +284,7 @@ prompt_hg() { prompt_dir() { if [[ $AGNOSTER_GIT_INLINE == 'true' ]] && $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then # Git repo and inline path enabled, hence only show the git root - prompt_segment "$AGNOSTER_DIR_BG" "$AGNOSTER_DIR_FG" "$(git rev-parse --show-toplevel | sed "s:^$HOME:~:")" + prompt_segment "$AGNOSTER_DIR_BG" "$AGNOSTER_DIR_FG" "$(git_toplevel | sed "s:^$HOME:~:")" else prompt_segment "$AGNOSTER_DIR_BG" "$AGNOSTER_DIR_FG" '%~' fi