diff options
author | Ben Hilburn <bhilburn@gmail.com> | 2016-04-11 22:16:37 +0300 |
---|---|---|
committer | Ben Hilburn <bhilburn@gmail.com> | 2016-04-11 22:16:37 +0300 |
commit | aec9d95295ef3966b835455c3340aa5f8b9367d9 (patch) | |
tree | d5b84dc5c71ebebe9322a2ea87a24d1c4049f8bd /powerlevel9k.zsh-theme | |
parent | b6e8e20b65a9242e22c1e72a60e1bfa35c03f6e3 (diff) | |
parent | 4ca6938801daf7158edc3b8e1922aa748d07eb18 (diff) |
Merge pull request #229 from alexlafroscia/add-package-name-shortening-strategy
Add shortening strategy based on package.json name
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 1a620a23..7da17f99 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -444,7 +444,43 @@ prompt_dir() { current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g") ;; truncate_from_right) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\//g") + current_path=$(truncatePathFromRight $(pwd | sed -e "s,^$HOME,~,") ) + ;; + truncate_with_package_name) + 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 + fi + + # 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 "\"name\""); then + name=$(echo $name | awk -F ':' '{print $2}' | awk -F '"' '{print $2}') + + # Instead of printing out the full path, print out the name of the package + # from the package.json and append the current subdirectory + current_path="`echo $name | tr -d '"'`$subdirectory_path" + else + current_path=$(truncatePathFromRight $(pwd | sed -e "s,^$HOME,~,") ) + fi ;; *) current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" |