Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1062 from dritter/truncate_package_json_upsearch
Browse files Browse the repository at this point in the history
Improve truncate_with_package_name strategy
  • Loading branch information
dritter authored Nov 15, 2018
2 parents 8fd2e28 + ab6c1b7 commit 98b1c06
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions segments/dir.p9k
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,12 @@ prompt_dir() {
fi
;;
truncate_with_package_name)
local name repo_path package_path current_dir zero

package_path=${PWD:A}
# Get the path of the Git repo, which should have the package.json file
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == "true" ]]; then
# Get path from the root of the git repository to the current dir
local gitPath=$(git rev-parse --show-prefix)
# Remove trailing slash from git path, so that we can
# remove that git path from the pwd.
gitPath=${gitPath%/}
package_path=${PWD%%$gitPath}
# Remove trailing slash
package_path=${package_path%/}
elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then
package_path=${PWD%%/.git*}
fi
# Search for the folder marker in the parent directories and
# buildup a pattern that is removed from the current path
# later on.
local -a markedFolders
markedFolders=( $(__p9k_upsearch "(${(j:|:)P9K_DIR_PACKAGE_FILES})") )
local package_path="${markedFolders[1]}"

# Replace the shortest possible match of the marked folder from
# the current path. Remove the amount of characters up to the
Expand Down

0 comments on commit 98b1c06

Please sign in to comment.