diff options
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-x | powerlevel9k.zsh-theme | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5fab0190..52b56f4e 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -655,12 +655,24 @@ 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}') + defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json) + local pkgFile="unknown" + for file in "${POWERLEVEL9K_DIR_PACKAGE_FILES[@]}"; do + if [[ -f "${package_path}/${file}" ]]; then + pkgFile="${package_path}/${file}" + break; + fi + done + + 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 @@ -891,15 +903,17 @@ prompt_ram() { local base='' local ramfree=0 if [[ "$OS" == "OSX" ]]; then + # Available = Free + Inactive + # See https://support.apple.com/en-us/HT201538 ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+') + ramfree=$((ramfree + $(vm_stat | grep "Pages inactive" | grep -o -E '[0-9]+'))) # Convert pages into Bytes ramfree=$(( ramfree * 4096 )) else if [[ "$OS" == "BSD" ]]; then - ramfree=$(vmstat | grep -E '([0-9]+\w+)+' | awk '{print $5}') - base='M' + ramfree=$(grep 'avail memory' /var/run/dmesg.boot | awk '{print $4}') else - ramfree=$(grep -o -E "MemFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") + ramfree=$(grep -o -E "MemAvailable:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*") base='K' fi fi |