Closed elsorino closed 5 years ago
Thanks for opening this issue.
Can you test master and see if the error still appears?
I've pushed memory support for macOS, please test it too. :+1:
@dylanaraps getting the following on master on macOS
./pfetch: line 247: syntax error near unexpected token `;;'
./pfetch: line 247: ` ;;'
What shell does macOS use for /bin/sh
?
This should be somewhat telling: /bin/sh --help
I've tested ash
, dash
and bash
and can't reproduce this issue.
I sympathize, seems weird
output from /bin/sh --help
bash-4.4$ /bin/sh --help
GNU bash, version 3.2.57(1)-release-(x86_64-apple-darwin18)
Usage: /bin/sh [GNU long option] [option] ...
/bin/sh [GNU long option] [option] script-file ...
GNU long options:
--debug
--debugger
--dump-po-strings
--dump-strings
--help
--init-file
--login
--noediting
--noprofile
--norc
--posix
--protected
--rcfile
--restricted
--verbose
--version
--wordexp
Shell options:
-irsD or -c command or -O shopt_option (invocation only)
-abefhkmnptuvxBCHP or -o option
Type `/bin/sh -c "help set"' for more information about shell options.
Type `/bin/sh -c help' for more information about shell builtin commands.
Use the `bashbug' command to report bugs.
Ah, it's bash 3 acting as /bin/sh
.
Let me build bash 3 and test.
I can reproduce with bash 3:
-> pfetch
/home/goldie/.local/bin/pfetch: line 247: syntax error near unexpected token `;;'
/home/goldie/.local/bin/pfetch: line 247: ` ;;'
Fixed the error.
Yep it works now, used memory is shown as 0 though
./pfetch
.:' elso@elsos-iMac.local
_ :'_ os macOS
.'`_`-'_``. host iMac18,3
:________.-' kernel 18.7.0
:_______: uptime 20m
:_______`-; pkgs 93
`._.-._.' memory 0MiB / 16384MiB
This is the code (ignore the EOF indentation, it's GitHub):
# Used memory is calculated using the following "formula" (MacOS):
# wired + active + occupied * 4 / 1024
Darwin*)
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))
;;
From what I can see, this code should work.
Oh, is it vm_stat
and not vmstat
?
Try master now!
Works perfectly now
./pfetch
.:' elso@elsos-iMac.local
_ :'_ os macOS
.'`_`-'_``. host iMac18,3
:________.-' kernel 18.7.0
:_______: uptime 25m
:_______`-; pkgs 93
`._.-._.' memory 6735MiB / 16384MiB
Side note, is there intention to add hackintosh detection like neofetch has?
Is there a simpler method of detection other than:
if [[ "$(kextstat | grep -F -e "FakeSMC" -e "VirtualSMC")" != "" ]]; then
model="Hackintosh (SMBIOS: $(sysctl -n hw.model))"
?
What's the full output of kextstat
?
A simpler method of retrieving this information would be handy too:
if [[ "$kernel_name" == "Darwin" ]]; then
IFS=$'\n' read -d "" -ra sw_vers <<< "$(awk -F'<|>' '/key|string/ {print $3}' \
"/System/Library/CoreServices/SystemVersion.plist")"
for ((i=0;i<${#sw_vers[@]};i+=2)) {
case ${sw_vers[i]} in
ProductName) darwin_name=${sw_vers[i+1]} ;;
ProductVersion) osx_version=${sw_vers[i+1]} ;;
ProductBuildVersion) osx_build=${sw_vers[i+1]} ;;
esac
}
fi
There's:
% sw_vers
ProductName: Mac OS X
ProductVersion: 10.10.4
BuildVersion: 14E101A
But how fast/slow is it to execute? time sw_vers
?
time sw_vers
:
ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G95
real 0m0.017s
user 0m0.005s
sys 0m0.009s
What about?:
time awk -F'<|>' '/key|string/ {print $3}' "/System/Library/CoreServices/SystemVersion.plist"
ProductBuildVersion
18G95
ProductCopyright
1983-2019 Apple Inc.
ProductName
Mac OS X
ProductUserVisibleVersion
10.14.6
ProductVersion
10.14.6
iOSSupportVersion
12.3.1
real 0m0.005s
user 0m0.002s
sys 0m0.003s
Nice.
Full output of cat /System/Library/CoreServices/SystemVersion.plist
?
```
kextstat
Index Refs Address Size Wired Name (Version) UUID
cat /System/Library/CoreServices/SystemVersion.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ProductBuildVersion</key>
<string>18G95</string>
<key>ProductCopyright</key>
<string>1983-2019 Apple Inc.</string>
<key>ProductName</key>
<string>Mac OS X</string>
<key>ProductUserVisibleVersion</key>
<string>10.14.6</string>
<key>ProductVersion</key>
<string>10.14.6</string>
<key>iOSSupportVersion</key>
<string>12.3.1</string>
</dict>
</plist>
Added proper macOS detection: https://github.com/dylanaraps/pfetch/blob/master/pfetch#L126-L166
Please try it out. Working on Hackintosh detection now.
@elsorino time kextstat
?
Is the Hackintosh detection even reliable? From what I'm reading online it isn't. I think it's better we leave it to Neofetch.
If the new distribution detection works I'll go ahead and close this. Let me know :+1:
Looks like some extras were left in 18G95
?
.:' elso@elsos-iMac.local
_ :'_ os macOS Mojave 10.14.6 18G95
.'`_`-'_``. host iMac18,3
:________.-' kernel 18.7.0
:_______: uptime 1h 47m
:_______`-; pkgs 97
`._.-._.' memory 7974MiB / 16384MiB
That's:
ProductBuildVersion
18G95
Should I omit it?
Fixed.
.:' elso@elsos-iMac.local
_ :'_ os macOS Mojave 10.14.6
.'`_`-'_``. host iMac18,3
:________.-' kernel 18.7.0
:_______: uptime 1h 59m
:_______`-; pkgs 97
`._.-._.' memory 8451MiB / 16384MiB
Working good now!
Running script gives an error
In addition, here is the output of
vm_stat