forked from bhudgens/benvironment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatuses
More file actions
98 lines (85 loc) · 2.8 KB
/
statuses
File metadata and controls
98 lines (85 loc) · 2.8 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
#! /usr/bin/env bash
##############################################################################
## Settings
##############################################################################
export DIR_WORKING_PATH="${DIR_WORKING_PATH:-/tmp}"
export DIR_ANYBAR_INSTALL_PATH="${DIR_WORKING_PATH}/AnyBar.app"
export FILE_ANYBAR_TMP_ZIP="${DIR_WORKING_PATH}/anybar.tmp.zip"
export FIVE_DAYS_IN_SECONDS=$((86400 * 5))
export URL_ANYBAR_DOWNLOAD_ZIP="https://github.com/tonsky/AnyBar/releases/download/0.1.4/AnyBar-0.1.4.zip"
##############################################################################
## AnyBar Helpers
##############################################################################
# Function: install_anybar
#
# Install AnyBar if not already installed
install_anybar() {
pushd "${DIR_WORKING_PATH}" > /dev/null
curl -L -s -o "${FILE_ANYBAR_TMP_ZIP}" "${URL_ANYBAR_DOWNLOAD_ZIP}"
unzip "${FILE_ANYBAR_TMP_ZIP}"
# Strip security from app
xattr -dr com.apple.quarantine "${DIR_ANYBAR_INSTALL_PATH}"
popd > /dev/null
}
# Function: run_anybar <port>
#
# Install & Run AnyBar on <port>
# Will punt if port detected to be in-use
run_anybar() {
ANYBAR_PORT=${1:-1738}
# Done installing?
([ "${ANYBAR_INSTALLING}" != "${ANYBAR_PORT}" ] \
|| netstat -an | grep udp | grep ${ANYBAR_PORT} > /dev/null) && unset ANYBAR_INSTALLING
# Port used? - Silently skip install
netstat -an | grep udp | grep ${ANYBAR_PORT} > /dev/null && return
# Install if necessary
[ -d "${DIR_ANYBAR_INSTALL_PATH}" ] || install_anybar
pushd "${DIR_WORKING_PATH}" > /dev/null
[ -z "${ANYBAR_INSTALLING}" ] && ANYBAR_PORT="${ANYBAR_PORT}" open -na "${DIR_ANYBAR_INSTALL_PATH}"
ANYBAR_INSTALLING="${ANYBAR_PORT}"
popd > /dev/null
}
# Function: anybar <command> <port>
#
# Change the status of the anybar icon
# running on 'port'
anybar() {
ANYBAR_COMMAND="${1:-white}"
ANYBAR_PORT="${2:-1738}"
run_anybar "${ANYBAR_PORT}"
echo -n "${ANYBAR_COMMAND}" | nc -4u -w0 localhost "${ANYBAR_PORT}";
}
# Function: anybar_good
#
# Wrapper to flip anybar to green
anybar_good() {
anybar "green" "${1}"
}
# Function: anybar_bad
#
# Wrapper to flip anybar to exclamation
anybar_bad() {
anybar "exclamation" "${1}"
}
# Function: anybar_warn
#
# Wrapper to flip anybar to red
anybar_warn() {
anybar "red" "${1}"
}
# [ -n "${HIPCHAT_MENTION_NAME}" ] && set_anybar_status_for_my_devdb
statusAnything() {
export PORT_ANYBAR_STATUS_ANYTHING="5959"
anybar_good "${PORT_ANYBAR_STATUS_ANYTHING}"
$*
anybar_bad "${PORT_ANYBAR_STATUS_ANYTHING}"
}
cat << EOF >> "${BENVIRONMENT_HELP_FILE}"
${blue}
${white}## Status Anything
${blue}
- ${white}statusAnything \$cmd \$args ${blue}
Runs any command and leaves a status bar indicator
on your menu bar while the command is running. Green
while the command runs and red when it stops
EOF