From fcc4c573a887aa17c56b62a1606efaff61d41319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cenk=20G=C3=BCndo=C4=9Fan?= Date: Fri, 25 Mar 2016 22:37:00 +0100 Subject: [PATCH] [prompt] fix gitster path to reflect git repo allow optional parameter for short_pwd Closes #41 --- modules/prompt/functions/short_pwd | 4 +++- modules/prompt/themes/gitster.zsh-theme | 14 +++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/modules/prompt/functions/short_pwd b/modules/prompt/functions/short_pwd index dc93885..37950cc 100644 --- a/modules/prompt/functions/short_pwd +++ b/modules/prompt/functions/short_pwd @@ -1,8 +1,10 @@ # shortens the pwd for use in prompt -local current_dir="${PWD/#${HOME}/~}" +local current_dir="${1:-${PWD}}" local return_dir='~' +current_dir="${current_dir/#${HOME}/~}" + # if we aren't in ~ if [[ ${current_dir} != '~' ]]; then return_dir="${${${${(@j:/:M)${(@s:/:)current_dir}##.#?}:h}%/}//\%/%%}/${${current_dir:t}//\%/%%}" diff --git a/modules/prompt/themes/gitster.zsh-theme b/modules/prompt/themes/gitster.zsh-theme index 08af8c7..9a3bc32 100644 --- a/modules/prompt/themes/gitster.zsh-theme +++ b/modules/prompt/themes/gitster.zsh-theme @@ -8,17 +8,9 @@ gst_get_status() { } gst_get_pwd() { - git_root=${PWD} - while [[ ${git_root} != / && ! -e ${git_root}/.git ]]; do - git_root=${git_root:h} - done - if [[ ${git_root} = / ]]; then - unset git_root - prompt_short_dir="$(short_pwd)" - else - parent=${git_root%\/*} - prompt_short_dir=${"$(short_pwd)"#${parent}/} - fi + prompt_short_dir="$(short_pwd)" + git_root="$(command git rev-parse --show-toplevel 2> /dev/null)" && \ + prompt_short_dir="${prompt_short_dir#${$(short_pwd $git_root):h}/}" print ${prompt_short_dir} }