@@ -6,11 +6,11 @@ bash.' && exit 2)
6
6
7
7
# Detect the packager.
8
8
if [ -x /usr/local/bin/brew ]; then
9
- packager =homebrew
9
+ detectedpackager =homebrew
10
10
elif command -v port > /dev/null; then
11
- packager =macports
11
+ detectedpackager =macports
12
12
else
13
- packager =none
13
+ detectedpackager =none
14
14
fi
15
15
16
16
# Get the command line options
@@ -20,6 +20,9 @@ opt_offline=f
20
20
for arg in " $@ "
21
21
do
22
22
case " ${arg} " in
23
+ -p|--packager)
24
+ packager=$detectedpackager
25
+ ;;
23
26
-m|--macports)
24
27
packager=macports
25
28
;;
36
39
-h|--help)
37
40
echo " Usage: $0 [options]"
38
41
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."
40
44
echo " -b --nocolor Turn color off."
41
45
echo " -c --color Force the color on (overrides --nocolor)."
42
46
echo " -o --offline Disable the IP address check."
@@ -72,7 +76,7 @@ uptime=$(uptime | sed 's/.*up \([^,]*\), .*/\1/')
72
76
shell=" $SHELL "
73
77
terminal=" $TERM ${TERM_PROGRAM// _/ } "
74
78
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: "?" )}' )
76
80
77
81
# removes (R) and (TM) from the CPU name so it fits in a standard 80 window
78
82
cpu=$( echo " $cpu " | awk ' $1=$1' | sed ' s/([A-Z]\{1,2\})//g' )
@@ -115,7 +119,9 @@ fieldlist[${#fieldlist[@]}]="${textColor}Kernel:${normal} ${kernel}${normal}"
115
119
fieldlist[${# fieldlist[@]} ]=" ${textColor} Uptime:${normal} ${uptime}${normal} "
116
120
fieldlist[${# fieldlist[@]} ]=" ${textColor} Shell:${normal} ${shell}${normal} "
117
121
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
119
125
fieldlist[${# fieldlist[@]} ]=" ${textColor} CPU:${normal} ${cpu}${normal} "
120
126
fieldlist[${# fieldlist[@]} ]=" ${textColor} Memory:${normal} ${ram}${normal} "
121
127
fieldlist[${# fieldlist[@]} ]=" ${textColor} Disk:${normal} ${disk}${normal} "
0 commit comments