diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2019-09-25 08:07:42 +0300 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2019-09-25 08:07:42 +0300 |
| commit | 83e2df7f310a1292472f6f2d75a19f287a8924d4 (patch) | |
| tree | a1042515969117c38e6a5dbb2200af3f1955b5f9 | |
| parent | c87dd713a788bf1c59961f859222b7a211180f9f (diff) | |
| download | pfetch-83e2df7f310a1292472f6f2d75a19f287a8924d4.tar.gz | |
memort: macos support
| -rwxr-xr-x | pfetch | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -302,10 +302,30 @@ get_memory() { mem_full=$((mem_full / 1024)) ;; + # Used memory is calculated using the following "formula" (MacOS): + # wired + active + occupied * 4 / 1024 Darwin*) - # If you run macOS and can send me the full output of - # 'vm_stat' I'll be able to add full support here. mem_full=$(($(sysctl -n hw.memsize) / 1024 / 1024)) + + # Parse the 'vmstat' file splitting on ':' and '.'. + # The format of the file is 'key: 000.' and an additional + # split is used on '.' to filter it out. + while IFS=:. read -r key val; do + case $key in + *wired*|*active*|*occupied*) + mem_used=$((mem_used + ${val:-0})) + ;; + esac + + # Using '<<-EOF' is the only way to loop over a command's + # output without the use of a pipe ('|') or subshell. + # This ensures that any variables defined in the while loop + # are still accessible in the script. + done <<-EOF + $(vmstat) + EOF + + mem_used=$((mem_used * 4 / 1024)) ;; OpenBSD*) @@ -714,6 +734,11 @@ get_ascii() { while read -r line; do ascii_height=$((ascii_height + 1)) ascii_width=$((${#line} > ascii_width ? ${#line} : ascii_width)) + + # Using '<<-EOF' is the only way to loop over a command's + # output without the use of a pipe ('|') or subshell. + # This ensures that any variables defined in the while loop + # are still accessible in the script. done <<-EOF $(printf %s "$ascii" | sed 's/\[3.m//g') EOF @@ -758,6 +783,8 @@ main() { $(uname -sr) EOF + os=Darwin + # Always run 'get_os' for the purposes of detecting which ascii # art to display. get_os |
