Guest User

Archey OS X

a guest
Mar 22nd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # ------------------------------------------------------------
  3. #
  4. # /usr/local/bin/archey
  5. #
  6. #
  7. # Archey :: OS X
  8. #
  9. # Description: Tool (bash script) to display system information.
  10. # Includes an option/plugin to take screenshots.
  11. #
  12. # Version: 1.0.0
  13. # Author: Eric F (iEFdev)
  14. # Copyright: (c) 2015 Eric F
  15. # Licence: GNU General Public License v3
  16. #
  17. # Author notes: This is a modified version of: "archey-osx"
  18. # by Josh Finnie.
  19. # ↳ https://github.com/joshfinnie/archey-osx
  20. # ↳ http://joshfinnie.github.io/
  21. #
  22.  
  23.  
  24. # Settings
  25. # ------------------------------------------------------------
  26. # diskWarning (default: 1) with green/red colors
  27. # diskWarningThreshold (default: 20) % of diskspace left
  28. diskWarning=1;
  29. diskWarningThreshold=20;
  30.  
  31.  
  32. # Colors
  33. # ------------------------------------------------------------
  34. # 2 first lines = the apple and the labels
  35.  
  36. b_c="\033[1;36m"; # b_c = ascii:bold color
  37. n_c="\033[0;36m"; # n_c = ascii:normal color
  38. g_c="\033[0;32m"; # g_c = green color
  39. r_c="\033[0;31m"; # r_c = red color
  40. w_c="\033[5;31m"; # w_c = red color (warning) (5; = blinking)
  41. e_c="\033[0m"; # e_c = empty color (eg reset)
  42.  
  43.  
  44. # Archey variables
  45. # ------------------------------------------------------------
  46.  
  47. # User
  48. user=$(whoami);
  49.  
  50. # Hostname
  51. hostname=$(uname -n);
  52.  
  53. # Distro
  54. distro="$(sw_vers -productName) $(sw_vers -productVersion) ($(sw_vers -buildVersion))";
  55.  
  56. # Kernel
  57. kernel=$(uname -srm);
  58.  
  59. # Uptime: Example: "35 min" or "1 day, 12:35" or "1 day, 10 min"
  60. uptime=$(uptime | sed 's/ / /g' | sed 's/.*up \([^,].*\),.*/\1/' | sed 's/\([^,].*\),.*/\1/');
  61.  
  62. # Shell and Terminal
  63. shell="$SHELL";
  64. terminal="$TERM";
  65.  
  66. # Packages
  67. # Display nice if Homebrew isn't installed
  68. packages="`brew list -l | wc -l | awk '{ print $1 }'`";
  69.  
  70. # CPU (info)
  71. cpu=$(sysctl -n machdep.cpu.brand_string | sed -e 's/ */ /g' | sed 's/CPU\ //');
  72.  
  73.  
  74. # Memory section
  75. # ------------------------------------------------------------
  76. # Display: (used = red) (free = green) total
  77. #
  78. memSize=$(sysctl -n hw.memsize);
  79. memTotalRam="$((memSize/1000000000)) GB";
  80.  
  81. # Using vm_stat to get all the memory
  82. memFree=$(vm_stat | grep "free" | awk '{ print $3 }' | sed 's/\.//');
  83. memInactive=$(vm_stat | grep "Pages inactive" | awk '{ print $3 }' | sed 's/\.//');
  84. memSpec=$(vm_stat | grep "speculative" | awk '{ print $3 }' | sed 's/\.//');
  85. memWired=$(vm_stat | grep "wired" | awk '{ print $4 }' | sed 's/\.//');
  86. memActive=$(vm_stat | grep "Pages active" | awk '{ print $3 }' | sed 's/\.//');
  87.  
  88. # Used memory
  89. # These 3 are matching "1234M used" in: top (and Activity Monitor)
  90. memUsed=$((($memWired+$memActive+$memInactive)*4096/1024/1024));
  91.  
  92. # Total free
  93. memTotalFree=$((($memFree+$memSpec)*4096/1024/1024));
  94.  
  95. # [note]
  96. # I's a little bit of a mess, and slightly confusing. Size of total memory ($memTotalRam) is easy to
  97. # get, but adding up what's used seems it's using MiB instead of MB. Haven't figured out
  98. # a way to solve it. Did try a few different settings, but any ideas/suggestions/improvements
  99. # are welcome.
  100.  
  101. # RAM: (used) (free) total
  102. ram=`echo -e "$r_c($memUsed MB)$e_c $g_c($memTotalFree MB)$e_c / $memTotalRam"`;
  103.  
  104.  
  105. # Function _disk()
  106. # ------------------------------------------------------------
  107. # Display: used/N% of total (N available) (disk)
  108. #
  109. function _disk() {
  110.  
  111. if [[ $diskWarning == 0 ]]; then
  112.  
  113. # Without colors...
  114. disk=`df -Hl | head -2 | tail -1 | awk '{print $3"/"$5 " of " $2 " (" $4 " available) (" $1 ")"}' | sed 's/\/dev\///g'`;
  115. else
  116. # DiskWarning will show some red text when the space
  117. # left on disk is below the setting.
  118.  
  119. # used size
  120. uSize=`df -Hl | head -2 | tail -1 | awk '{ print $3}'`;
  121.  
  122. # used size (%)
  123. pSize=`df -Hl | head -2 | tail -1 | awk '{ print $5}'`;
  124.  
  125. # total size
  126. totSize=`df -Hl | head -2 | tail -1 | awk '{ printf "of %-1s", $2}'`;
  127.  
  128. # available size
  129. aSize=`df -Hl | head -2 | tail -1 | awk '{ printf "(%-1s available)", $4}'`;
  130.  
  131. # diskNsN
  132. mPoint=`df -Hl | head -2 | tail -1 | awk '{printf "(%-1s)", $1}' | sed 's/\/dev\///g'`;
  133.  
  134. # Ok... If the disk is more than 80% full?
  135. if [[ $pSize > $((100-$diskWarningThreshold)) ]]; then
  136. pSize="$w_c$pSize$e_c"; # Blink % + red color
  137. aSize="$r_c$aSize$e_c"; # red color
  138. else
  139. pSize="$g_c$pSize$e_c"; # % in green color
  140. fi
  141.  
  142. # Sum up ...
  143. disk="$uSize/$pSize $totSize $aSize $mPoint";
  144. fi
  145. }
  146. # load
  147. _disk;
  148.  
  149.  
  150. # IP Private
  151. ip=`ipconfig getifaddr en0`;
  152.  
  153. # IP Public
  154. # ip2=$(curl -s -o - ip.appspot.com);
  155.  
  156.  
  157. # Archey :: OS X
  158. # ------------------------------------------------------------
  159. echo -e "
  160. $b_c ## $n_c User:$e_c $user
  161. $b_c ##### $n_c Hostname:$e_c $hostname
  162. $b_c ##### $n_c Distro:$e_c $distro
  163. $b_c ##### $n_c Kernel:$e_c $kernel
  164. $b_c ### $n_c Uptime:$e_c $uptime
  165. $b_c ##### ##### $n_c Shell:$e_c $shell
  166. $b_c #####################$n_c# Terminal:$e_c $terminal
  167. $b_c ###################$n_c####### Packages:$e_c $packages
  168. $b_c ################$n_c######### CPU:$e_c $cpu
  169. $b_c #############$n_c########### RAM:$e_c $ram
  170. $b_c ##########$n_c############# Disk:$e_c $disk
  171. $b_c #######$n_c################# Ip:$e_c $ip
  172. $b_c #####$n_c##################### $e_c
  173. $b_c ###$n_c#######################$e_c
  174. $b_c #$n_c####################### $e_c
  175. $n_c ##################### $e_c
  176. $n_c ################## $e_c
  177. $n_c #### #### $e_c
  178. ";
  179.  
  180.  
  181. # Plugins
  182. # ------------------------------------------------------------
  183.  
  184. # Import the archey.s plugin (if installed)
  185. # The plugin will add a screenshot feature
  186. if [ -f `which archey.s` ] && [[ $1 != '' ]]; then
  187. . `which archey.s`;
  188. fi
  189.  
  190. exit;
Advertisement
Add Comment
Please, Sign In to add comment