aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hilburn <bhilburn@gmail.com>2016-06-14 20:28:08 +0300
committerGitHub <noreply@github.com>2016-06-14 20:28:08 +0300
commit467742286f42c1b72f3992121eafd5b5658ffc81 (patch)
treec059529737c46c2b2f32f9c68463d5b1c8bbf632
parent45ff1d1b5129986b89cfb0ca6bbe455847c97827 (diff)
parentd720b725e8644072a240be924eec09d1f0d21edb (diff)
Merge pull request #275 from andjscott/prompt_dir_shortening
Handle shorting path when in the .git directory
-rwxr-xr-xpowerlevel9k.zsh-theme28
1 files changed, 10 insertions, 18 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 3053afbd..ef6d0a5a 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -467,26 +467,18 @@ prompt_dir() {
local name repo_path package_path current_dir zero
# Get the path of the Git repo, which should have the package.json file
- if repo_path=$(git rev-parse --git-dir 2>/dev/null); then
- if [[ "$repo_path" == ".git" ]]; then
- # If the current path is the root of the project, then the package path is
- # the current directory and we don't want to append anything to represent
- # the path to a subdirectory
- package_path="."
- subdirectory_path=""
- else
- # If the current path is something else, get the path to the package.json
- # file by finding the repo path and removing the '.git` from the path
- package_path=${repo_path:0:-4}
- zero='%([BSUbfksu]|([FB]|){*})'
- current_dir=$(pwd)
- # Then, find the length of the package_path string, and save the
- # subdirectory path as a substring of the current directory's path from 0
- # to the length of the package path's string
- subdirectory_path=$(truncatePathFromRight "/${current_dir:${#${(S%%)package_path//$~zero/}}}")
- fi
+ if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == "true" ]]; then
+ package_path=$(git rev-parse --show-toplevel)
+ elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then
+ package_path=${$(pwd)%%/.git*}
fi
+ zero='%([BSUbfksu]|([FB]|){*})'
+ current_dir=$(pwd)
+ # Then, find the length of the package_path string, and save the
+ # subdirectory path as a substring of the current directory's path from 0
+ # to the length of the package path's string
+ subdirectory_path=$(truncatePathFromRight "${current_dir:${#${(S%%)package_path//$~zero/}}}")
# Parse the 'name' from the package.json; if there are any problems, just
# print the file path
if name=$( cat "$package_path/package.json" 2> /dev/null | grep -m 1 "\"name\""); then