-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.helpers
executable file
·212 lines (188 loc) · 5.77 KB
/
.helpers
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
# NOTE: These GitHub helpers work, but also consider using the `gh` CLI. See
# https://cli.github.com/.
GITHUB="https://github.com/pishoyg/coptic"
DOMAIN="remnqymi.com"
# crum opens a Crum page on ⲣⲉⲙⲛ̀Ⲭⲏⲙⲓ.
crum () {
for KEY in "${@}"; do
open "https://${DOMAIN}/crum/${KEY}.html"
done
}
dawoud () {
for KEY in "${@}"; do
open "https://${DOMAIN}/dawoud/$((KEY + 16)).jpg"
done
}
# issues open issue pages in GitHub.
issues () {
for ISSUE in "${@}"; do
open "${GITHUB}/issues/${ISSUE}"
done
}
# github opens the GitHub page for the project.
github () {
open "${GITHUB}"
}
# commits opens the commits in GitHub.
commits () {
for ISSUE in "${@}"; do
open "${GITHUB}/commit/$(git rev-parse "${ISSUE}")"
done
}
# Print the Makefile recipe without executing it.
alias makedr='make --dry-run'
# Colors are used to prettify outputs.
export RESET='\033[0m'
export BLACK='\033[0;30m'
export RED='\033[0;31m'
export GREEN='\033[0;32m'
export YELLOW='\033[0;33m'
export BLUE='\033[0;34m'
export PURPLE='\033[0;35m'
export CYAN='\033[0;36m'
export WHITE='\033[0;37m'
color () {
echo -e "${!1}${*:2}${RESET}"
}
# _grep runs `grep` but changes the exit code 1 to 0.
# `grep` returns an exit code of 0 if matches are found, 1 if NO matches are
# found, or something else if it runs into an error.
# _grep is essentially a version of `grep` that considers the absence of a
# match to be a success.
_grep() {
grep "${@}"
RES=$?
if [[ "${RES}" == "1" || "${RES}" == "0" ]]; then
return 0
fi
return "${RES}"
}
# Find, excluding "garbage" files and directories.
findex () {
find "${1}" \
-not -path "./.git/*" \
-not -path "./.git" \
-not -name ".DS_Store" \
-not -path "*/__pycache__/*" \
-not -path "*/__pycache__" \
-not -path "./coptic.egg-info/*" \
-not -path "./coptic.egg-info" \
-not -path "./.mypy_cache/*" \
-not -path "./.mypy_cache" \
-not -path "./.ruff_cache/*" \
-not -path "./.ruff_cache" \
-not -path "./node_modules/*" \
-not -path "./node_modules" \
-not -path "bible/stshenouda.org/data/output/epub/*" \
-not -path "bible/stshenouda.org/data/output/epub" \
-not -path "flashcards/data/output/anki/*" \
-not -path "flashcards/data/output/anki/" \
-not -name "package-lock.json" \
-not -name "package.json" \
-not -name ".env" \
-not -path "./archive/*" \
-not -path "./archive" \
"${@:2}"
}
# Find, excluding "garbage", and data!
findexx () {
findex "${1}" \
-not -path "*/data/*" \
"${@:2}"
}
# Find files, excluding "garbage".
ffindex () {
findex "${1}" -type f "${@:2}"
}
# Find files, excluding "garbage", and data.
ffindexx () {
findexx "${1}" -type f "${@:2}"
}
# Grep, excluding "garbage" and binary files.
grepex () {
ffindex "${1}" -exec grep "${@:2}" --binary-files="without-match" --color=auto --with-filename --line-number {} \;
}
# Grep, excluding "garbage", binary files, and data.
grepexx () {
ffindexx "${1}" -exec grep "${@:2}" --binary-files="without-match" --color=auto --with-filename --line-number {} \;
}
# Search for TODO's.
# NOTE: We "mangle" the regex using extra parentheses in order to prevent it
# from matching itself.
todo() {
HELP="${BLUE}Display TODO markers in the repo.
Run ${GREEN}todo \"\${ISSUE_NUMBER}\" ${BLUE}to show TODOs for a specific issue.
Run ${GREEN}todo \"stray\" ${BLUE}to show TODOs without an associated issue.
Run ${GREEN}todo --help ${BLUE}to display this message.${RESET}"
PATTERN='TODO(:) '
PARAM="${1}"
if (( "$#" > 1 )); then
echo -e "${RED}Too many parameters!${RESET}"
echo -e "${HELP}"
return 1
fi
if [[ "${PARAM}" == "--help" ]]; then
echo -e "${HELP}"
return 0
fi
# TODO: (#66) There will be no need to support stray TODO's once they have
# been eradicated and banned.
if [[ "${PARAM}" == "stray" ]]; then
# Search for TODO's without an assigned issue.
PATTERN="${PATTERN}(?!\(#[0-9]+\))"
elif [ -n "${PARAM}" ]; then
if ! echo "${PARAM}" | grep --quiet --extended-regexp '^[0-9]+$'; then
echo -e "${RED}Invalid parameter.${RESET}"
echo -e "${HELP}"
return 1
fi
PATTERN="${PATTERN}\(#${PARAM}\)"
CLOSED=$(gh issue view "${PARAM}" --json "closed" --jq ".closed")
if [[ "${CLOSED}" == "true" ]]; then
echo -e "${RED}Warning: Issue ${YELLOW}#${PARAM} ${RED}is closed!"\
"See ${YELLOW}${GITHUB}/issues/${PARAM}${RED}.${RESET}"
fi
fi
grepexx . --perl-regexp "${PATTERN}"
}
# Search for dead Python code, or `dead` disable markers.
pydead () {
dead --exclude=archive | while read -r MATCH; do
SYMBOL="$(echo "${MATCH}" | awk '{ print $1 }')"
MESSAGE="$(echo "${MATCH}" | awk '{ $1=""; $NF=""; print }')"
FILE="$(echo "${MATCH}" | awk '{ print $NF }' | cut --field=1 --delimiter=":")"
LINE_NUM="$(echo "${MATCH}" | awk '{ print $NF }' | cut --field=2 --delimiter=":")"
echo -e "${RED}${SYMBOL}${RESET}${MESSAGE}${PURPLE}${FILE}${RESET}:${GREEN}${LINE_NUM}${RESET}"
done
grepexx . '# dead: disable' --include="*.py"
}
alias gits='git -C "${SITE_DIR}"'
alias img='./dictionary/marcion.sourceforge.net/img_helper.py'
alias app='./dictionary/marcion.sourceforge.net/appendices_helper.py'
_senses() {
words=()
# Check if input is provided through a pipe.
if [ -p /dev/stdin ]; then
while IFS= read -r line; do
words+=("$line")
done
else
# Otherwise, read from function arguments.
words=("$@")
fi
echo -n "{"
array_length=${#words[@]}
for (( i=1; i<=array_length; i++ )); do
printf '"%d": "%s"' "$i" "${words[i]}"
if [ "$i" -le $((array_length - 1)) ]; then
echo -n ", "
fi
done
echo -n "}"
}
senses() {
SENSES=$(_senses "$@")
echo "${SENSES}" | pbcopy
echo "${SENSES}"
}