Skip to content
This repository was archived by the owner on Feb 14, 2020. It is now read-only.

Commit 11c680a

Browse files
committed
1. ioreg -c -r is much faster, thx to meal (http://hints.macworld.com/article.php?story=20100130123935998) for the tested awk 'grep'
2. disable package manager per default since it costs more than 300ms saved: 500ms \!
1 parent 644ac87 commit 11c680a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

bin/archey

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ bash.' && exit 2)
66

77
# Detect the packager.
88
if [ -x /usr/local/bin/brew ]; then
9-
packager=homebrew
9+
detectedpackager=homebrew
1010
elif command -v port >/dev/null; then
11-
packager=macports
11+
detectedpackager=macports
1212
else
13-
packager=none
13+
detectedpackager=none
1414
fi
1515

1616
# Get the command line options
@@ -20,6 +20,9 @@ opt_offline=f
2020
for arg in "$@"
2121
do
2222
case "${arg}" in
23+
-p|--packager)
24+
packager=$detectedpackager
25+
;;
2326
-m|--macports)
2427
packager=macports
2528
;;
@@ -36,7 +39,8 @@ do
3639
-h|--help)
3740
echo "Usage: $0 [options]"
3841
echo
39-
echo " -m --macports Use MacPorts as package system (default packager: ${packager})."
42+
echo " -p --packager Use auto detected package system (default packager: ${detectedpackager})."
43+
echo " -m --macports Force use MacPorts as package system."
4044
echo " -b --nocolor Turn color off."
4145
echo " -c --color Force the color on (overrides --nocolor)."
4246
echo " -o --offline Disable the IP address check."
@@ -72,7 +76,7 @@ uptime=$(uptime | sed 's/.*up \([^,]*\), .*/\1/')
7276
shell="$SHELL"
7377
terminal="$TERM ${TERM_PROGRAM//_/ }"
7478
cpu=$(sysctl -n machdep.cpu.brand_string)
75-
battery=$(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}')
79+
battery=$(ioreg -c AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
7680

7781
# removes (R) and (TM) from the CPU name so it fits in a standard 80 window
7882
cpu=$(echo "$cpu" | awk '$1=$1' | sed 's/([A-Z]\{1,2\})//g')
@@ -115,7 +119,9 @@ fieldlist[${#fieldlist[@]}]="${textColor}Kernel:${normal} ${kernel}${normal}"
115119
fieldlist[${#fieldlist[@]}]="${textColor}Uptime:${normal} ${uptime}${normal}"
116120
fieldlist[${#fieldlist[@]}]="${textColor}Shell:${normal} ${shell}${normal}"
117121
fieldlist[${#fieldlist[@]}]="${textColor}Terminal:${normal} ${terminal}${normal}"
118-
fieldlist[${#fieldlist[@]}]="${textColor}Packages:${normal} ${packagehandler}${normal}"
122+
if [ ${packagehandler} -ne 0 ]; then
123+
fieldlist[${#fieldlist[@]}]="${textColor}Packages:${normal} ${packagehandler}${normal}"
124+
fi
119125
fieldlist[${#fieldlist[@]}]="${textColor}CPU:${normal} ${cpu}${normal}"
120126
fieldlist[${#fieldlist[@]}]="${textColor}Memory:${normal} ${ram}${normal}"
121127
fieldlist[${#fieldlist[@]}]="${textColor}Disk:${normal} ${disk}${normal}"

0 commit comments

Comments
 (0)