-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
Copy path_common.sh
executable file
·58 lines (55 loc) · 1.37 KB
/
_common.sh
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
#!/bin/bash
#
# Note: this is a shell script to be included in all other scripts. It subsumes common functionality
# across shell scripts in most other shell scripts.
# Encode (used to encode image to give to Gemini)
function _base64_encode_mac_or_linux() {
IMAGE="$1"
#data=$(base64 -i "$IMAGE" -o -) # Mac
#data=$(base64 -w 0 "$IMAGE") # linux
if [[ $(uname) == "Darwin" ]]; then
base64 -i "$IMAGE" -o -
else
base64 -w 0 "$IMAGE"
fi
}
# Decode (used in TTS to decode MP3)
function _base64_decode_mac_or_linux() {
IMAGE="$1"
if [[ $(uname) == "Darwin" ]]; then
base64 --decode -i "$IMAGE" -o -
else
base64 "$IMAGE" --decode
fi
}
# assumes you have the output in file 't'
function show_errors_and_exit() {
echo Woops. Some Errors found. See error in t:
_redden <t # cat t | _redden
exit 42
}
function _red() {
echo -en "\033[1;31m$*\033[0m\n"
}
# make the STD in RED :) (proper bash filter)
function _redden() {
while read -r row; do echo -en "\033[0;31m$row\033[0m\n"; done
}
function _green() {
echo -en "\033[1;32m$*\033[0m\n"
}
function _white() {
echo -en "\033[1;37m$*\033[0m\n"
}
function _yellow() {
echo -en "\033[1;33m$*\033[0m\n"
}
# If you dont have lolcat your life is going to be more miserable.
# To fix your life: `gem install lolcat`
function _lolcat() {
if which lolcat >/dev/null; then
lolcat
else
cat
fi
}