mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-18 13:41:56 +00:00
Fix parsing package name from complex package.json files
when using `truncate_with_package_name` strategy.
This commit is contained in:
parent
94293b0f94
commit
17671d3ee3
1 changed files with 7 additions and 4 deletions
|
@ -655,12 +655,15 @@ prompt_dir() {
|
||||||
subdirectory_path=$(truncatePathFromRight "${current_dir:${#${(S%%)package_path//$~zero/}}}")
|
subdirectory_path=$(truncatePathFromRight "${current_dir:${#${(S%%)package_path//$~zero/}}}")
|
||||||
# Parse the 'name' from the package.json; if there are any problems, just
|
# Parse the 'name' from the package.json; if there are any problems, just
|
||||||
# print the file path
|
# print the file path
|
||||||
if name=$( cat "$package_path/package.json" 2> /dev/null | grep -m 1 "\"name\""); then
|
local pkgFile="${package_path}/package.json"
|
||||||
name=$(echo $name | awk -F ':' '{print $2}' | awk -F '"' '{print $2}')
|
local packageName=$(jq '.name' ${pkgFile} 2> /dev/null \
|
||||||
|
|| node -e 'console.log(require(process.argv[1]).name);' ${pkgFile} 2>/dev/null \
|
||||||
|
|| cat "${pkgFile}" 2> /dev/null | grep -m 1 "\"name\"" | awk -F ':' '{print $2}' | awk -F '"' '{print $2}' 2>/dev/null \
|
||||||
|
)
|
||||||
|
if [[ -n "${packageName}" ]]; then
|
||||||
# Instead of printing out the full path, print out the name of the package
|
# Instead of printing out the full path, print out the name of the package
|
||||||
# from the package.json and append the current subdirectory
|
# from the package.json and append the current subdirectory
|
||||||
current_path="`echo $name | tr -d '"'`$subdirectory_path"
|
current_path="`echo $packageName | tr -d '"'`$subdirectory_path"
|
||||||
else
|
else
|
||||||
current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" )
|
current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" )
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue