diff options
author | Dominik Ritter <dritter03@googlemail.com> | 2017-02-24 01:30:55 +0300 |
---|---|---|
committer | Dominik Ritter <dritter03@googlemail.com> | 2017-02-24 01:30:55 +0300 |
commit | a0aa5ccbfcabda100249f710de9297ffa1444fbb (patch) | |
tree | b89d11ad3ad3ea58847b376547535c62b482f78a /powerlevel9k.zsh-theme | |
parent | 02df303651c13a05eaef73192f853120481f0d33 (diff) |
Fix parsing package name from complex package.json files
when using `truncate_with_package_name` strategy.
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5fab0190..b6fef65a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -655,12 +655,15 @@ prompt_dir() { 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 - name=$(echo $name | awk -F ':' '{print $2}' | awk -F '"' '{print $2}') - + local pkgFile="${package_path}/package.json" + 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 # 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 current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) fi |