forked from nathanchance/env
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos_darwin
More file actions
executable file
·189 lines (170 loc) · 6.4 KB
/
os_darwin
File metadata and controls
executable file
·189 lines (170 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/usr/bin/env bash
#
# Utility and terminal setup functions for Mac
#
# Copyright (C) 2017 Nathan Chancellor
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
function darwin_aliases() {
alias sshfb='ssh nathan@nchancellor.net'
alias repo="cd ${HOME}/Documents/Repos"
alias subs="cd ${HOME}/Documents/Repos/Substratum"
alias scpt="cd ${HOME}/Documents/Repos/Scripts"
alias misc="cd ${HOME}/Documents/Misc"
}
function darwin_prompt() {
source ~/.git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWUPSTREAM=auto
export PROMPT_COMMAND='__git_ps1 "\[\033[01;31m\]\u@\h \[\033[01;33m\]\w\[\033[01;36m\]" " \[\033[39m\]\$\[\033[0m\] "'
}
function getOS() {
prodVers=$(prodVers=$(sw_vers|grep ProductVersion);echo ${prodVers:15})
buildVers=$(buildVers=$(sw_vers|grep BuildVersion);echo ${buildVers:14})
echo "macOS ${prodVers} ${buildVers}"
}
function getUptime() {
unset uptime
boot=$(sysctl -n kern.boottime | cut -d "=" -f 2 | cut -d "," -f 1)
now=$(date +%s)
uptime=$(($now-$boot))
if [[ -n ${uptime} ]]; then
secs=$((${uptime}%60))
mins=$((${uptime}/60%60))
hours=$((${uptime}/3600%24))
days=$((${uptime}/86400))
uptime="${mins}m"
[[ "${hours}" -ne "0" ]] && uptime="${hours}h ${uptime}"
[[ "${days}" -ne "0" ]] && uptime="${days}d ${uptime}"
fi
echo ${uptime}
}
function getCPU() {
cpu=$(machine)
if [[ $cpu == "ppc750" ]]; then
cpu="IBM PowerPC G3"
elif [[ $cpu == "ppc7400" || $cpu == "ppc7450" ]]; then
cpu="IBM PowerPC G4"
elif [[ $cpu == "ppc970" ]]; then
cpu="IBM PowerPC G5"
else
cpu=$(sysctl -n machdep.cpu.brand_string)
fi
REGEXP="-E"
if [[ "${cpun}" -gt "1" ]]; then
cpun="${cpun}x "
else
cpun=""
fi
if [ -z "$cpufreq" ]; then
cpu="${cpun}${cpu}"
else
cpu="$cpu @ ${cpun}${cpufreq}"
fi
thermal="/sys/class/hwmon/hwmon0/temp1_input"
if [ -e $thermal ]; then
temp=$(bc <<< "scale=1; $(cat $thermal)/1000")
fi
if [ -n "$temp" ]; then
cpu="$cpu [${temp}°C]"
fi
cpu=$(sed $REGEXP 's/\([tT][mM]\)|\([Rr]\)|[pP]rocessor|CPU//g' <<< "${cpu}" | xargs)
echo ${cpu}
}
function getDiskUsage() {
diskusage="Unknown"
if type -p df >/dev/null 2>&1; then
totaldisk=$(df -H / 2>/dev/null | tail -1)
disktotal=$(awk '{print $2}' <<< "${totaldisk}")
diskused=$(awk '{print $3}' <<< "${totaldisk}")
diskusedper=$(awk '{print $5}' <<< "${totaldisk}")
fi
echo "${diskused} out of ${disktotal} (${diskusedper})"
}
function getMemUsage() {
totalmem=$(echo "$(sysctl -n hw.memsize)" / 1024^2 | bc)
wiredmem=$(vm_stat | grep wired | awk '{ print $4 }' | sed 's/\.//')
activemem=$(vm_stat | grep ' active' | awk '{ print $3 }' | sed 's/\.//')
compressedmem=$(vm_stat | grep occupied | awk '{ print $5 }' | sed 's/\.//')
if [[ ! -z "$compressedmem | tr -d" ]]; then
compressedmem=0
fi
usedmem=$(((${wiredmem} + ${activemem} + ${compressedmem}) * 4 / 1024))
percent=$(echo $(echo "scale = 2; (${usedmem} / ${totalmem})" | bc -l | awk -F '.' '{print $2}') | sed s/^0*//g)
if [[ -z ${percent} ]]; then
percent=0
fi
echo "${usedmem} MiB out of ${totalmem} MiB (${percent}%)"
}
function motd() {
echo ""
echo ""
echo " \$\$\$\$\$\$\$\$\ \$\$\ \$\$\$\$\$\$\ \$\$\$\$\$\$\ \$\$\ \$\$\ \$\$\$\$\$\$\$\$\ \$\$\$\$\$\$\ \$\$\$\$\$\$\$\ "
echo " \$\$ _____|\$\$ | \$\$ __\$\$\ \$\$ __\$\$\ \$\$ | \$\$ | \__\$\$ __|\$\$ __\$\$\ \$\$ __\$\$\ "
echo " \$\$ | \$\$ | \$\$ / \$\$ |\$\$ / \__|\$\$ | \$\$ | \$\$ | \$\$ / \$\$ |\$\$ | \$\$ |"
echo " \$\$\$\$\$\ \$\$ | \$\$\$\$\$\$\$\$ |\\$\$\$\$\$\$\ \$\$\$\$\$\$\$\$ | \$\$ | \$\$ | \$\$ |\$\$\$\$\$\$\$ |"
echo " \$\$ __| \$\$ | \$\$ __\$\$ | \____\$\$\ \$\$ __\$\$ | \$\$ | \$\$ | \$\$ |\$\$ ____/ "
echo " \$\$ | \$\$ | \$\$ | \$\$ |\$\$\ \$\$ |\$\$ | \$\$ | \$\$ | \$\$ | \$\$ |\$\$ | "
echo " \$\$ | \$\$\$\$\$\$\$\$\ \$\$ | \$\$ |\\$\$\$\$\$\$ |\$\$ | \$\$ | \$\$ | \$\$\$\$\$\$ |\$\$ | "
echo " \__| \________|\__| \__| \______/ \__| \__| \__| \______/ \__| "
echo ""
echo ""
echo " Today's date : $(date "+%B %d, %Y (%A)")"
echo " Current time : $(date "+%I:%M %p %Z")"
echo " Operating system : $(getOS)"
echo " Kernel version : $(uname -srm)"
echo " Processor : $(getCPU)"
echo " Memory usage : $(getMemUsage)"
echo " Disk usage : $(getDiskUsage)"
echo " Uptime : $(getUptime)"
echo ""
echo ""
}
function darwin_setup() {
export ANDROID_HOME=${HOME}/Library/Android/SDK
add_to_path_pre /usr/local/sbin
add_to_path_post ${HOME}/Documents/Repos/Scripts
add_to_path_post ${HOME}/Library/Android/SDK/build-tools/26.0.0-rc2
add_to_path_post ${HOME}/Library/Android/SDK/build-tools/25.0.3
add_to_path_post ${HOME}/Library/Android/SDK/ndk-bundle
add_to_path_pre /Library/Frameworks/Python.framework/Versions/3.6/bin
motd
}
function upterm() {
local MAKE="make ${JOBS_FLAG}"
cd ${HOME}/Documents/Repos/iTerm2
git fetch origin
git rebase origin/master
[[ $? -ne 0 ]] && echo "Error updating repo!" && return
${MAKE} clean
${MAKE} Development
${MAKE} install
}
function nf() {
echo
neofetch \
--kernel_shorthand off \
--distro_shorthand tiny \
--os_arch off \
--uptime_shorthand tiny \
--speed_shorthand on \
--refresh_rate on \
--install_time off
echo
echo
}
function update() {
brew update
brew upgrade
}