-
Notifications
You must be signed in to change notification settings - Fork 5
/
imports.sh
executable file
·160 lines (133 loc) · 4.13 KB
/
imports.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
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
#!/usr/bin/env zsh
## Define colors
red=$'\e[1;31m'
green=$'\e[1;32m'
blue=$'\e[1;34m'
magenta=$'\e[1;35m'
cyan=$'\e[1;36m'
white=$'\e[0m'
function log () {
echo "🟢 [$(date +'%H:%M:%S')] $1"
}
function log_warning () {
echo "🟡 [$(date +'%H:%M:%S')] $1"
}
function log_error () {
echo >&2 "🔴 [$(date +'%H:%M:%S')] $1"
}
# https://stackoverflow.com/a/17841619/971329
function join_by {
local IFS="$1"; shift; echo "$*";
}
function loadEnvironment () {
# Ignores commented lines
ENV_FILE="$(dirname "$0")/../.env"
if [ -f "$ENV_FILE" ]; then
export "$(grep -v '^#' "$ENV_FILE" | xargs)"
fi
}
function checkInstalledJq () {
command -v jq >/dev/null 2>&1 || {
echo >&2 "jq missing - Install using \"brew install jq\"."; exit 1;
}
}
function checkInstalledLocalise () {
command -v lokalise >/dev/null 2>&1 || {
echo >&2 "lokalise missing - Install using \"brew tap lokalise/brew; brew install lokalise\"."; exit 1;
}
}
function checkInstalledImageMagick () {
command -v convert >/dev/null 2>&1 || {
echo >&2 "imagemagick missing - Install using \"brew install imagemagick\"."; exit 1;
}
}
function trim () {
awk '{$1=$1};1'
}
function mdsee() {
HTMLFILE="$(mktemp -u).html"
jq --slurp --raw-input '{"text": "\(.)", "mode": "markdown"}' "$1" | \
curl -s --data @- https://api.github.com/markdown > "$HTMLFILE"
echo "$HTMLFILE"
open "$HTMLFILE"
}
# Create and commit changelog item
function cci() {
if [[ -z $1 ]]; then
echo "Please provide a changelog title / issue number combination in the format <title #number>. Exit." && return
fi
title=$(echo $1 | sed 's/ #[0-9]*$//')
number=$(echo $1 | sed 's/.*#//')
account=$(git config github.user)
while true; do
printf 'Is the account name "%s" correct? [Y/n]: ' "$green$account$white"
read yn
case $yn in
[Nn]* )
echo "Please add your GitHub username to the local config using the following account and run the command again:$green git config --local github.user \<username\>"
return;;
* )
break;; # continue with suggested account
esac
done
entry="* [#$number](https://github.com/dbdrive/beiwagen/pull/$number): $title - [@$account](https://github.com/$account)."
while true; do
printf 'Do you want to commit the change log entry:%s? [Y/n]: ' "$green $entry $white"
read yn
case $yn in
[Nn]* )
break;; # cancel process
* )
echo "$entry" > "changelog/$number.md"
git add "changelog/$number.md"
git commit -m "Add Changelog Item"
git push
break;;
esac
done
}
# Open man page in textedit
function manv() {
if [[ -z $1 ]]; then
echo "Please provide the command you want to view the man page for. Exit." && return
fi
MANWIDTH=80 MANPAGER='col -bx' man "$1" | subl
}
# Easily create ASC auth header
function asc_auth_header() {
echo "Bearer $(ruby ~/dev/scripts/jwt.rb "$ASC_AUTH_KEY" "$ASC_AUTH_KEY_ID" "$ASC_AUTH_KEY_ISSUER_ID")"
}
function collage() {
cd "$(mktemp -d)"
# Round corers of input image
for IMAGE in "${@[@]}"
do
BASENAME="$(basename $IMAGE)"
read -r width height <<< $(magick -ping "$IMAGE" -format "%w %h" info:)
magick \
-size ${width}x${height} xc:none \
-fill white \
-draw "roundRectangle 0,0 ${width},${height} 50,50" "$IMAGE" \
-compose SrcIn \
-composite "$BASENAME"
done
# Make the collage
montage * \
-background none \
-shadow \
-geometry '+25+25' collage.heic
# Make gradient background
read -r width height <<< $(magick -ping "collage.heic" -format "%w %h" info:)
magick -size ${width}x${height} radial-gradient:#fffffe-lightgray "gradient.heic"
# Put collage on gradient background
composite -gravity center "collage.heic" "gradient.heic" "collage-gradient.heic"
# Round corers of final image
magick \
-size ${width}x${height} xc:none \
-fill white \
-draw "roundRectangle 0,0 ${width},${height} 50,50" "collage-gradient.heic" \
-compose SrcIn \
-composite final.heic
echo "Find your files in \"$(pwd)\""
cd -
}