archey.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/bin/bash
  2. # archey-osx 1.5.2 (https://github.com/obihann/archey-osx/)
  3. # test to see if bash supports arrays
  4. arraytest[0]='test' || (echo 'Error: Arrays are not supported in this version of
  5. bash.' && exit 2)
  6. # Detect the packager.
  7. #if [ -x /usr/local/bin/brew ]; then
  8. #detectedpackager=homebrew
  9. #elif command -v port >/dev/null; then
  10. #detectedpackager=macports
  11. #else
  12. #detectedpackager=none
  13. #fi
  14. # Get the command line options
  15. opt_nocolor=f
  16. opt_force_color=f
  17. opt_offline=f
  18. for arg in "$@"
  19. do
  20. case "${arg}" in
  21. -p|--packager)
  22. packager=$detectedpackager
  23. ;;
  24. -m|--macports)
  25. packager=macports
  26. ;;
  27. -b|--nocolor)
  28. opt_nocolor=t
  29. ;;
  30. -c|--color)
  31. opt_nocolor=f
  32. opt_force_color=t
  33. ;;
  34. -o|--offline)
  35. opt_offline=t
  36. ;;
  37. -h|--help)
  38. echo "Archey OS X 1.5.2"
  39. echo
  40. echo "Usage: $0 [options]"
  41. echo
  42. echo " -p --packager Use auto detected package system (default packager: ${detectedpackager})."
  43. echo " -m --macports Force use MacPorts as package system."
  44. echo " -b --nocolor Turn color off."
  45. echo " -c --color Force the color on (overrides --nocolor)."
  46. echo " -o --offline Disable the IP address check."
  47. exit 0
  48. ;;
  49. *)
  50. echo "Unknown argument: $1" 1>&2
  51. echo "For help, use: $0 --help" 1>&2
  52. exit 1
  53. ;;
  54. esac
  55. done
  56. # System Variables
  57. user=$(whoami)
  58. hostname=$(hostname | sed 's/.local//g')
  59. #if [[ "${opt_offline}" = f ]]; then
  60. #ipfile="${HOME}/.archey-ip"
  61. #if [ -a "$ipfile" ] && test `find "$ipfile" -mmin -360`; then
  62. #while read -r line; do
  63. #ip="$line"
  64. #done < "$ipfile"
  65. #else
  66. #ip=$(dig +short myip.opendns.com @resolver1.opendns.com)
  67. #echo $ip > "$ipfile"
  68. #fi
  69. #fi
  70. distro="OS X $(sw_vers -productVersion)"
  71. kernel=$(uname)
  72. uptime=$(uptime | sed 's/.*up \([^,]*\), .*/\1/')
  73. shell="$SHELL"
  74. terminal="$TERM ${TERM_PROGRAM//_/ }"
  75. cpu=$(sysctl -n machdep.cpu.brand_string)
  76. #battery=$(ioreg -c AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
  77. battery=$(pmset -g batt | xargs | egrep "\d+%" -o)
  78. # removes (R) and (TM) from the CPU name so it fits in a standard 80 window
  79. cpu=$(echo "$cpu" | awk '$1=$1' | sed 's/([A-Z]\{1,2\})//g')
  80. ram="$(( $(sysctl -n hw.memsize) / 1024 ** 3 )) GB"
  81. disk=$(df | head -2 | tail -1 | awk '{print $5}')
  82. # Set up colors if:
  83. # * stdout is a tty
  84. # * the user hasn't turned it off
  85. # * or if we're forcing color
  86. if [[ ( -t 1 && "${opt_nocolor}" = f) || "${opt_force_color}" = t ]]
  87. then
  88. RED=$(tput setaf 1 2>/dev/null)
  89. GREEN=$(tput setaf 2 2>/dev/null)
  90. YELLOW=$(tput setaf 3 2>/dev/null)
  91. BLUE=$(tput setaf 4 2>/dev/null)
  92. PURPLE=$(tput setaf 5 2>/dev/null)
  93. textColor=$(tput setaf 6 2>/dev/null)
  94. normal=$(tput sgr0 2>/dev/null)
  95. fi
  96. case "${packager}" in
  97. homebrew)
  98. packagehandler=$(brew list -1 | wc -l | awk '{print $1 }')
  99. ;;
  100. macports)
  101. packagehandler=$(port installed | wc -l | awk '{print $1 }')
  102. ;;
  103. *)
  104. packagehandler=0
  105. ;;
  106. esac
  107. fieldlist[${#fieldlist[@]}]="${textColor}User:${normal} ${user}${normal}"
  108. fieldlist[${#fieldlist[@]}]="${textColor}Hostname:${normal} ${hostname}${normal}"
  109. fieldlist[${#fieldlist[@]}]="${textColor}Distro:${normal} ${distro}${normal}"
  110. fieldlist[${#fieldlist[@]}]="${textColor}Kernel:${normal} ${kernel}${normal}"
  111. fieldlist[${#fieldlist[@]}]="${textColor}Uptime:${normal} ${uptime}${normal}"
  112. fieldlist[${#fieldlist[@]}]="${textColor}Shell:${normal} ${shell}${normal}"
  113. fieldlist[${#fieldlist[@]}]="${textColor}Terminal:${normal} ${terminal}${normal}"
  114. fieldlist[${#fieldlist[@]}]="${textColor}Terminal Size:${normal} $(tput lines) x $(tput cols)"
  115. #if [ ${packagehandler} -ne 0 ]; then
  116. #fieldlist[${#fieldlist[@]}]="${textColor}Packages:${normal} ${packagehandler}${normal}"
  117. #fi
  118. fieldlist[${#fieldlist[@]}]="${textColor}CPU:${normal} ${cpu}${normal}"
  119. fieldlist[${#fieldlist[@]}]="${textColor}Memory:${normal} ${ram}${normal}"
  120. fieldlist[${#fieldlist[@]}]="${textColor}Disk:${normal} ${disk}${normal}"
  121. #if [ ! -z $battery ]; then
  122. #fi
  123. fieldlist[${#fieldlist[@]}]="${textColor}Battery:${normal} ${battery}${normal}"
  124. #if [ "${opt_offline}" = f ]; then
  125. #fieldlist[${#fieldlist[@]}]="${textColor}IP Address:${normal} ${ip}${normal}"
  126. #fi
  127. fieldlist[${#fieldlist[@]}]="${textColor}Date:${normal} $(date)${normal}"
  128. logofile=${ARCHEY_LOGO_FILE:-"${HOME}/.config/archey-logo"}
  129. if [ -a "$logofile" ]
  130. then
  131. source "$logofile"
  132. else
  133. # The ${foo# } is a cheat so that it lines up here as well
  134. # as when run.
  135. echo -e "
  136. ${GREEN# } ####### ${fieldlist[0]}
  137. ${GREEN# } ######## ${fieldlist[1]}
  138. ${GREEN# } ##### ${fieldlist[2]}
  139. ${GREEN# } ##### ${fieldlist[3]}
  140. ${YELLOW# } ###### ${fieldlist[4]}
  141. ${YELLOW# } ######## ${fieldlist[5]}
  142. ${RED# } ########### ${fieldlist[6]}
  143. ${RED# } ##### ##### ${fieldlist[7]}
  144. ${RED# } ##### ##### ${fieldlist[8]}
  145. ${PURPLE# } ##### ##### ${fieldlist[9]}
  146. ${PURPLE# } ##### ##### ## ${fieldlist[10]}
  147. ${BLUE# } ##### ########## ${fieldlist[11]}
  148. ${BLUE# } ##### ####### ${fieldlist[12]}
  149. ${normal}
  150. "
  151. fi