Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.96 KB | None | 0 0
  1.  appleseed v1.0.0 Is a command line widget (CLW), I designed for macOS
  2. and iTerm2. It's a flexible platform for process automation and added
  3. eye candy. It utilizes imgcat to view image files inside the terminal
  4. with the help of shell integration. • For best results, launch in a
  5. tall by thin proportioned shell.
  6.  
  7. #!/usr/bin/env bash
  8. # appleseed is a command line widget (CLW), designed for macOS and iTerm2.
  9.  
  10. #Variables
  11. args=("$@")
  12. endscript="false"
  13. imgcat="/Users/matthew/.iterm2/imgcat"
  14. minutes="10"
  15. status1="Working.. "
  16. copying="Copying.. "
  17. host=$HOSTNAME
  18. DIR="$HOME/git/appleseed/img"
  19. BDIR="$HOME/git/appleseed/backup" #your backup directory
  20. prefix=""
  21. IFS='
  22. '
  23.  
  24. #What do you want to backup?
  25. dotfile0="$HOME/.zshrc"
  26. dotfile1="$HOME/.oh-my-zsh/themes/trident.zsh-theme"
  27. dotfile2="$HOME/Library/Fonts/Hack-Regular.ttf"
  28. dotfile3="$HOME/.tmux.conf"
  29. dotfile4="/etc/tmux.conf.local"
  30. dotfile5="$HOME/osxui/okeanos/demo/trident.coffee"
  31. #dotfile6=""
  32. #dotfile7=""
  33. #dotfile8=""
  34. many="6"
  35.  
  36. #Colors
  37. reset="$(tput sgr0)"
  38. #black="$(tput bold; tput setaf 0)"
  39. blue="$(tput bold; tput setaf 4)"
  40. cyan="$(tput bold; tput setaf 6)"
  41. green="$(tput bold; tput setaf 2)"
  42. purple="$(tput bold; tput setaf 5)"
  43. red="$(tput bold; tput setaf 1)"
  44. #white="$(tput bold; tput setaf 7)"
  45. yellow="$(tput bold; tput setaf 3)"
  46. orange=$(tput bold; tput setaf 166);
  47. #violet=$(tput bold; tput setaf 61);
  48. header="${cyan}[ ${reset}${green}${reset}${cyan} appleseed @ ${blue}${host}${reset} ${cyan}]${reset}"
  49. backup="${purple}Backup:${reset}"
  50. packages="${purple}Packages:${reset}"
  51. network="${purple}Network:${reset}"
  52. resources="${purple}Resources:${reset}"
  53.  
  54. #Arguments
  55. version=${cyan}1.0.0${reset}
  56.  
  57. license="
  58. ${cyan}${reset} appleseed v${version}
  59.  
  60. ${purple}Copyright (C) 2018 Matthew A. Brassey${reset}
  61.  
  62. This program is free software: you can redistribute it and/or modify
  63. it under the terms of the GNU General Public License as published by
  64. the Free Software Foundation, either version 3 of the License, or
  65. (at your option) any later version.
  66.  
  67. This program is distributed in the hope that it will be useful,
  68. but WITHOUT ANY WARRANTY; without even the implied warranty of
  69. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  70. GNU General Public License for more details.
  71.  
  72. You should have received a copy of the GNU General Public License
  73. along with this program. If not, see <http://www.gnu.org/licenses/>.
  74. "
  75.  
  76. help="
  77. ${cyan}Usage:${cyan}${green} ./appleseed.sh ${reset}${purple}[--help|--version]${reset}
  78.  
  79. ${cyan}[options]${reset}${green}
  80. --license Show lisense information.
  81. --about What is appleseed?${reset}
  82. "
  83.  
  84. about="
  85. ${cyan}${reset} appleseed v${version}
  86.  
  87. Is a command line widget (CLW), designed for macOS and iTerm2. For best results,
  88. launch in a tall by thin proportioned shell.
  89. "
  90.  
  91. #Functions
  92. function panel() {
  93. start=$SECONDS
  94. clear
  95. echo "$header"
  96. echo ""
  97. echo "$backup"
  98. backup
  99. echo ""
  100. echo "$packages"
  101. macOS
  102. homebrew
  103. echo ""
  104. echo "$network"
  105. network
  106. echo ""
  107. echo "$resources"
  108. system
  109. echo ""
  110. graphix
  111.  
  112. #Sleep sequence
  113. completed
  114. secs=$((minutes * 60))
  115. while [ $secs -gt 0 ]; do
  116. echo -ne "${blue}╰────╼${reset}${green} Re-launch in:${reset} ${cyan}$secs\033[0Ks\r${reset}"
  117. sleep 1
  118. : $((secs--))
  119. done
  120. }
  121.  
  122. function graphix() {
  123. if [[ -d "${DIR}" ]]
  124. then
  125. # shellcheck disable=SC2207
  126. # taken care (through setting IFS)
  127. file_matrix=($(ls "${DIR}"))
  128. num_files=(${#file_matrix[*]})
  129. $imgcat "${DIR}/${file_matrix[$((RANDOM%num_files))]}"
  130. fi
  131. }
  132.  
  133. function homebrew() {
  134. echo "${cyan}[${reset} ${blue}Homebrew: ${reset} ${yellow}$status1${reset} ${cyan}]${reset}"
  135. temp0="$(brew update 2>&1)"
  136. if [[ "$temp0" = *"Already"* ]]; then
  137. status4="${green}Updated!${reset}"
  138. img_brew="✔"
  139. echo "${cyan}[${reset} ${blue}Homebrew: ${reset} ${green}$status4${reset} ${cyan}]${reset}"
  140. else
  141. status4="${orange}Missing!${reset}"
  142. echo "${cyan}[${reset} ${blue}Homebrew: ${reset} ${green}$status4${reset} ${cyan}]${reset}"
  143. img_brew="${orange}✗${reset}${cyan}"
  144. if [[ "$temp0" = *"Updated"* ]]; then
  145. echo "${cyan}[${reset} ${green}✔ ${temp0:0:14}${reset} ${cyan}]${reset}"
  146. img_brew="✔"
  147. fi
  148. fi
  149. brew_ver="$(brew --version 2>&1)"
  150. # shellcheck disable=SC2206
  151. # taken care (through setting IFS)
  152. brew_ver_num=(${brew_ver[@]})
  153. echo "${cyan}[${reset}${cyan} $img_brew ${brew_ver_num[0]}${reset} ${cyan}]${reset}"
  154. temp0=""
  155. }
  156.  
  157. function macOS() {
  158. echo "${cyan}[${reset} ${blue}macOS: ${reset} ${yellow}$status1${reset} ${cyan}]${reset}"
  159. temp="$(softwareupdate -l 2>&1)"
  160. # temp="No"
  161. temp2="$(echo "$temp"|grep "No" 2>&1)"
  162. if [ -s "$temp2" ]
  163. then
  164. status3="${red}Missing!${reset}" #need root to actually update macOS
  165. img_os="${orange}✗${reset}${cyan}"
  166. else
  167. status3="${green}Updated!${reset}"
  168. img_os="✔"
  169. fi
  170. echo "${cyan}[${reset} ${blue}macOS: ${reset} ${yellow}$status3${reset} ${cyan}]${reset}"
  171. os_ver="$(sw_vers -productVersion 2>&1)"
  172. echo "${cyan}[${reset} ${cyan}$img_os macOS ${reset}${cyan}$os_ver${reset} ${cyan}]${reset}"
  173. temp2=""
  174. }
  175.  
  176. function network(){
  177. public_ip=$(wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
  178. city_raw=$(curl ipinfo.io/"$public_ip" 2>&1|grep city|sed 's/(.*)../1/')
  179. city=${city_raw:11}
  180. region_raw=$(curl ipinfo.io/"$public_ip" 2>&1|grep region|sed 's/(.*)../1/')
  181. region=${region_raw:13}
  182. country_raw=$(curl ipinfo.io/"$public_ip" 2>&1|grep country|sed 's/(.*)../1/')
  183. country=${country_raw:14}
  184. echo "• ${blue}IP: ${reset}${green}$public_ip${reset}"
  185. if [ -s "$city" ]
  186. then
  187. :
  188. else
  189. echo "• ${blue}City: ${reset}${green}$city${reset}"
  190. fi
  191. if [ -s "$region" ]
  192. then
  193. :
  194. else
  195. if [ "$region" == "$city" ]
  196. then
  197. :
  198. else
  199. echo "• ${blue}Region: ${reset}${green}$region${reset}"
  200. fi
  201. fi
  202. if [ "$country" != "US" ]
  203. then
  204. vpn="${cyan}✔ ${reset}${green}VPN${reset}"
  205. else
  206. vpn="${orange}✗ ${reset}${yellow}VPN${reset}"
  207. fi
  208. echo "• ${blue}Country: ${reset}${green}$country${reset} $vpn"
  209. }
  210.  
  211. function backup(){
  212. count="0"
  213. echo "${cyan}[${reset} ${blue}dotfiles: ${reset}${yellow}$copying${reset} ${cyan}]${reset}"
  214.  
  215. if [ -f "$dotfile0" ]
  216. then
  217. cp "$dotfile0" "${BDIR}" 2>&1
  218. ((count++))
  219. else
  220. :
  221. fi
  222.  
  223. if [ -f "$dotfile1" ]
  224. then
  225. cp "$dotfile1" "${BDIR}" 2>&1
  226. ((count++))
  227. else
  228. :
  229. fi
  230.  
  231. if [ -f "$dotfile2" ]
  232. then
  233. cp "$dotfile2" "${BDIR}" 2>&1
  234. ((count++))
  235. else
  236. :
  237. fi
  238.  
  239. if [ -f "$dotfile3" ]
  240. then
  241. cp "$dotfile3" "${BDIR}" 2>&1
  242. ((count++))
  243. else
  244. :
  245. fi
  246.  
  247. if [ -f "$dotfile4" ]
  248. then
  249. cp "$dotfile4" "${BDIR}" 2>&1
  250. ((count++))
  251. else
  252. :
  253. fi
  254.  
  255. if [ -f "$dotfile5" ]
  256. then
  257. cp "$dotfile5" "${BDIR}" 2>&1
  258. ((count++))
  259. else
  260. :
  261. fi
  262.  
  263. # if [ -f "$dotfile6" ]
  264. # then
  265. # :
  266. # ((count++))
  267. # else
  268. # :
  269. # fi
  270.  
  271. if [ $count -eq $many ]
  272. then
  273. img_backup="✔"
  274. else
  275. img_backup="${orange}✗${reset}"
  276. fi
  277. echo "${cyan}[${reset} ${cyan}$img_backup Copied: ${reset}${green}$count${reset}/${cyan}$many${reset}${cyan} files!${reset} ${cyan}]${reset}"
  278. }
  279.  
  280. function system(){
  281. cpu2=$(top -l 2 -n 0 -F | grep -Eo ' d*.d+% idle' | tail -1 | awk -F% -v prefix="$prefix" '{ printf "%s%.1f%%n", prefix, 100 - $1 }') # – mklement0
  282. cpu1=${cpu2::-3}
  283. cpu0=$((100 - cpu1))
  284. if [ "$cpu0" -lt "10" ]
  285. then
  286. cpu=" ${orange}$cpu0${reset}${green}%${reset} "
  287. else
  288. cpu="${green}$cpu0${reset}${green}%${reset} "
  289. fi
  290. capacity=$(df -h /)
  291. capacity2="$capacity[2]"
  292. capacity2=${capacity:110:-30}
  293. capacity3=$((100 - capacity2))
  294. echo "${cyan}[ ${reset}${blue}SSD:${reset} ${green}$capacity3${reset}${green}%${reset}${cyan} ]${reset} ${cyan}[ ${reset}${blue}CPU:${reset} $cpu${cyan}]${reset}"
  295. }
  296.  
  297. function completed(){
  298. duration=$(( SECONDS - start ))
  299. echo "${blue}╭────╼${reset}${purple} Completed in: ${reset}${cyan}$duration${reset}${cyan}s${reset}"
  300. }
  301.  
  302. #Arguments
  303. for ((arg=0;arg<"${#args[@]}";arg++)); do
  304. [ "${args[$arg]}" == "--version" ] && echo "${version}" && exit
  305. [ "${args[$arg]}" == "--help" ] && echo "${help}" && exit
  306. [ "${args[$arg]}" == "--license" ] && echo "${license}" && exit
  307. [ "${args[$arg]}" == "--about" ] && echo "${about}" && exit
  308. #[ "${args[$arg]}" == "--" ] && echo ${args[$arg]}
  309. done
  310.  
  311. #Activate panel
  312. while [ $endscript = "false" ]
  313. do
  314. panel
  315. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement