cmc/dotfiles
Using GNU Stow to manage my dotfiles.
clone: git clone https://gitbay.org/cmc/dotfiles.git
main: macos/motd/motd.sh · raw
1BOLD='\033[1m'
2DIM='\033[2m'
3RESET='\033[0m'
4
5HOST=$(scutil --get ComputerName 2>/dev/null || hostname)
6
7IP=$(ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null)
8IP=${IP:-unavailable}
9
10SSID=$(networksetup -getairportnetwork en0 2>/dev/null | sed 's/^Current Wi-Fi Network: //')
11case "$SSID" in
12 ""|"You are not associated with an AirPort network.")
13 SSID="unavailable"
14 ;;
15esac
16
17BATTERY=$(pmset -g batt 2>/dev/null | awk -F'; *' '
18 NR==2 {
19 gsub(/^ +| +$/, "", $2)
20 gsub(/^ +| +$/, "", $3)
21 sub(/ present: true$/, "", $3)
22 print $2 ", " $3
23 }
24')
25BATTERY=${BATTERY:-unavailable}
26
27UPTIME=$(uptime | sed 's/^.*up //; s/, [0-9]* user.*//; s/, load averages.*//')
28UPTIME=${UPTIME:-unavailable}
29
30if profiles status -type enrollment 2>/dev/null | grep -qi "MDM enrollment: Yes"; then
31 MANAGED="yes"
32else
33 MANAGED="no"
34fi
35
36VPN="unavailable"
37
38if command -v mullvad >/dev/null 2>&1; then
39 STATUS=$(mullvad status 2>/dev/null)
40 VPN=$(printf '%s\n' "$STATUS" | head -1)
41 VPN=${VPN:-unavailable}
42fi
43
44printf "\n"
45printf " ${BOLD}%s${RESET} ${DIM}%s${RESET}\n" "$USER" "$(uname -sr)"
46printf " ${DIM}%-14s${RESET}%s\n" "host" "$HOST"
47printf " ${DIM}%-14s${RESET}%s\n" "managed" "$MANAGED"
48printf " ${DIM}%-14s${RESET}%s\n" "wifi" "$SSID"
49printf " ${DIM}%-14s${RESET}%s\n" "ip" "$IP"
50printf " ${DIM}%-14s${RESET}%s\n" "mullvad" "$VPN"
51printf " ${DIM}%-14s${RESET}%s\n" "battery" "$BATTERY"
52printf " ${DIM}%-14s${RESET}%s\n" "uptime" "$UPTIME"
53printf "\n"
54