Advertisement
Arctis

sys info.sh

Sep 6th, 2015
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.91 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ==USER==
  4. user=$(whoami)
  5.  
  6. # ==HOSTNAME==
  7. hostname=$(HOSTNAME | sed 's/.local//g')
  8. # if hostname is 35 characters, truncates to make it fit on std. 80 window
  9. if [ ${#HOSTNAME} -gt 35 ]
  10. then
  11.    hostname=${HOSTNAME:0:35}
  12. fi
  13.  
  14. # ==MODEL==
  15. model=$(system_profiler SPHardwareDataType -detailLevel mini | awk '/Model Identifier/ { print $3 }')
  16.  
  17. # ==GRAPHICS==
  18. graphics=$(system_profiler SPDisplaysDataType |
  19. awk '/Model/{for (i=1; i<=NF-2; i++) $i = $(i+2); NF-=2; print}' | paste -sd "/" -)
  20.  
  21. graphicsnoBrand=$(system_profiler SPDisplaysDataType |
  22. awk '/Model/{for (i=1; i<=NF-3; i++) $i = $(i+3); NF-=3; print}' | paste -sd "/" -)
  23. # Use system_profiler to find graphics cards, then awk to find 'Model'
  24. # Output of this step is lines such as this:
  25. #  Chipset Model: Intel HD Graphics
  26. #  Chipset Model: NVIDIA GeForce GT 330M
  27. # Use awk with a loop to print the arguments after Model: to end of line
  28. # Use paste to join multiple lines together with a slash if necessary.
  29. # Sample output:
  30. #  graphics:        Intel HD Graphics/NVIDIA GeForce GT 330M
  31. #  graphicsnoBrand: HD Graphics/GeForce GT 330M
  32.  
  33. # ==VERSION==
  34. versionNumber=$(sw_vers -productVersion) # Finds version number
  35.  
  36. versionShort=${versionNumber:0:4}  # Cut sting to 1 decimal place for calculation
  37.  
  38. #music=$(./nowplaying)
  39. music="test"
  40. case $versionShort in
  41.     10.9)
  42.         versionString="Mavericks"
  43.         ;;
  44.     10.8)
  45.         versionString="Mountian Lion"
  46.         ;;
  47.     10.7)
  48.         versionString="Lion"
  49.         ;;
  50.     10.6)
  51.         versionString="Snow Leopard"
  52.         ;;
  53.     10.5)
  54.         versionString="Leopard"
  55.         ;;
  56.     10.4)
  57.         versionString="Tiger"
  58.         ;;
  59.     10.3)
  60.         versionString="Panther"
  61.         ;;
  62.     10.2)
  63.         versionString="Jaguar"
  64.         ;;
  65.     10.1)
  66.         versionString="el Capitan"
  67.         ;;
  68.     10.0)
  69.         versionString="Cheetah"
  70.         ;;
  71.  
  72. esac
  73.  
  74. version="$versionString"
  75.  
  76. # ==KERNEL==
  77. kernel="XNU"
  78.  
  79. # ==UPTIME==
  80. uptime=$(uptime | sed 's/.*up \([^,]*\), .*/\1/')
  81.  
  82. # ==SHELL==
  83. shell="$SHELL"
  84. wm="Quartz"
  85.  
  86. # ==TERMINAL==
  87. terminal="$TERM"
  88.  
  89. # ==PACKAGE MANAGER==
  90.  
  91. # check if brew or macports is installed, then total there packages and set packagehandler
  92. if [ -e /usr/local/bin/brew ]
  93. then
  94.     brewpackages=$(brew list -l | tail -n +2 | wc -l)
  95.     packagehandler=$brewpackages
  96. elif [ -f /opt/local/bin/port ] #don't think this is the right directory, need to check later.
  97. then
  98.     macportpackages="`port installed | wc -l | awk '{print $1 }'`"
  99.     packagehandler=$macportpackages
  100. fi
  101.  
  102. # ==CPU==
  103. cpu=$(sysctl -n machdep.cpu.brand_string)
  104. # removes (R) and (TM) from the CPU name so it fits in a standard 80 window
  105. cpu=$(echo "$cpu" | awk '$1=$1' | sed 's/([A-Z]\{1,2\})//g')
  106.  
  107. # ==MEMORY==
  108. mem=$(sysctl -n hw.memsize)
  109. mem="$((mem/1000000000)) GB"
  110.  
  111. # ==DISK==
  112. disk=`df -Hl | head -2 | tail -1`
  113. dpercent=`echo $disk | awk '{print $5}'`
  114. dfree=`echo $disk | awk '{print $4}'`
  115. dused=`echo $disk | awk '{print $3}'`
  116. dcapacity=`echo $disk | awk '{print $2}'`
  117.  
  118. # Colors Variables
  119. red="1"
  120. green="2"
  121. yellow="3"
  122. blue="4"
  123. purple="5"
  124. lightblue="6"
  125. grey="7"
  126.  
  127. textColor=$(tput setaf $red)
  128. normal=$(tput sgr0)
  129. GR='\033[00;32m'
  130.                         YE='\033[00;33m'
  131.                         LR='\033[01;31m'
  132.                         RE='\033[00;31m'
  133.                         PU='\033[00;35m'
  134.                         CY='\033[00;36m'
  135.                         BL='\033[00;34m'
  136.  
  137. # While loops for script arguments
  138. while [ $# -gt 0 ]
  139. do
  140.     case "$1" in
  141.  
  142.     -c|--color)
  143.             GR='\033[00;32m'
  144.             YE='\033[00;33m'
  145.             LR='\033[01;31m'
  146.             RE='\033[00;31m'
  147.             PU='\033[00;35m'
  148.             CY='\033[00;36m'
  149.             BL='\033[00;34m'
  150.             shift
  151.             ;;
  152.     -red)
  153.             textColor=$(tput setaf $red)
  154.             shift
  155.             ;;
  156.     -green)
  157.             textColor=$(tput setaf $green)
  158.             shift
  159.             ;;
  160.     -yellow)
  161.             textColor=$(tput setaf $yellow)
  162.             shift
  163.             ;;
  164.     -blue)
  165.             textColor=$(tput setaf $blue)
  166.             shift
  167.             ;;
  168.     -purple)
  169.             textColor=$(tput setaf $purple)
  170.             shift
  171.             ;;
  172.     -grey)
  173.             textColor=$(tput setaf $grey)
  174.             shift
  175.             ;;
  176.     *)
  177.             break
  178.             ;;
  179.     esac
  180. done
  181.  
  182.  
  183. userText="${textColor}Host${normal}"
  184. hostnameText="${textColor}Hostname:${normal}"
  185. modelText="${textColor}Model ${normal}"
  186. versionText="${textColor}OS${normal}"
  187. kernelText="${textColor}Kernel:${normal}"
  188. uptimeText="${textColor}Uptime${normal}"
  189. shellText="${BL}${textColor}Shell${normal}"
  190. terminalText="${textColor}Terminal:${normal}"
  191. packagehandlerText="${textColor}Packages:${normal}"
  192. cpuText="${textColor}CPU:${normal}"
  193. memoryText="${textColor}Memory:${normal}"
  194. graphicsText="${textColor}Graphics:$normal"
  195. diskText="${textColor}Disk${normal}"
  196. musicText="${textColor}Music${normal}"
  197. wmText="${textColor}WM${normal}"
  198.  
  199.  
  200. echo -e "
  201. ${GR}                       ▄▆█
  202. ${GR}                     ▗███▀
  203. ${GR}                     ███▀
  204. ${GR}               ▂▂   ▗█▛  ▂▂▂
  205. ${GR}            ▄██████▄▄▄▄██████▄
  206. ${GR}          ▄████████████████████▖
  207. ${YE}         ▟████████████████████▛▘            $userText  $user@$(HOSTNAME | sed 's/.local//g')
  208. ${YE}        ▟████████████████████▘                $versionText  $version
  209. ${RE}        ████████████████████▌                 ${textColor}WM  ${normal}$wm
  210. ${RE}        ████████████████████▙             $uptimeText  $uptime
  211. ${RE}        ▐████████████████████▄              $diskText  $dpercent
  212. ${RE}         ██████████████████████▄           $modelText $model
  213. ${PU}         ▝██████████████████████
  214. ${PU}          ▀████████████████████▛
  215. ${BL}            ▀█████████████████▀
  216. ${BL}             ▝▀██▛▀▔  ▔▀▀██▀▀
  217. ${normal}
  218. "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement