-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail.trash
More file actions
executable file
·239 lines (201 loc) · 6.48 KB
/
mail.trash
File metadata and controls
executable file
·239 lines (201 loc) · 6.48 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
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
# wrapper for neomutt
declare -A ENV=(
[root]=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
[config]="${MAILRC:-$HOME/.mailrc}"
[data]="${MAILBOX:-$HOME/.mail}"
[message]= # post-execution messages and warnings go here
[pwd]=$(pwd)
[error]=0
[connection]=
[mode]=
)
declare -A FILE=(
[log]=
[help]=
)
declare -A ARG=(
[input]="$@"
[debug]=0
[help]=0
[op1]=0
[op2]=0
[operands]=
)
#########################################################
main() {
initialize # setup environment and check for missing files
parse "$@" # break input for analysis
dispatch # execute the operation
terminate # execute post-script tasks regardless of operation
}
# prepare program for execution
initialize() {
check_internet_connection # set ARG[connection] if exists
[[ ! "${ARG[connection]}" ]] && connect_internet
}
check_internet_connection() {
echo "checking conection... (syke)"
}
connect_internet() {
:
}
parse() {
ignore= # tells the last case to NOT treat as operand
# Iterate over arguments using a while loop
while [[ $# -gt 0 ]]; do
case "$1" in
debug)
ARG[debug]=1
ignore=yes
;;&
op1)
if is_false ${ARG[op1]} && not "${ENV[mode]}" && not "$ignore" ; then
ARG[op1]=1
ENV[mode]=OP1
ignore=yes # tells the last case to ignore this one cuz its an operator keyword
fi
;;&
op2)
if is_false ${ARG[op2]} && not "${ENV[mode]}" && not "$ignore" ; then
ARG[op2]=1
ENV[mode]=OP2
ignore=yes # tells the last case to ignore this one cuz its an operator keyword
fi ;;&
*)
[[ ! "$ignore" ]] && ARG[operands]+=" $1"
ignore= #reset
;;
esac ; shift # discard argument
done
}
dispatch() {
:
EMAIL_PASSWORD=$(pass "$EMAIL_PASSWORD") neomutt -F "$MUTTRC" # temporary
# make sure to allow using the original mail commad
}
terminate() {
final_message="${ENV[message]}"
# error_number=${ENV[error]}
# error_msg="${ERROR[$error_number]}"
# if debug is true, reveal variables
is_true ${ARG[debug]} && reveal_variables
# if there are any errors, print
[[ $error_number -gt 0 ]] && echo -e "$error_msg"
# if there are any final messages, print
[[ -n "$final_message" ]] && echo -e "\n$final_message"
exit $error_number
}
print_help() {
bat $(get_file help)
}
# Loop through the keys of the associative array and print key-value pairs
reveal_variables() {
local yellow="\033[33m"
local green="\033[32m"
local red="\033[31m"
local purple="\033[35m"
local cyan="\033[36m"
local reset="\033[0m"
echo -e "--- ARGUMENTS ---"
for key in "${!ARG[@]}"; do
value="${ARG[$key]}"
value="${value%"${value##*[![:space:]]}"}" # Trim trailing whitespace
value="${value#"${value%%[![:space:]]*}"}" # Trim leading whitespace
color="$reset"
if [[ $value == 'null' ]]; then
value="" # Null value
elif [[ -z $value ]]; then
# value="EMPTY" # Empty string
# color=$cyan # Empty value
:
elif [[ $value == '1' ]]; then
color=$green # True value
elif [[ $value == '0' ]]; then
color=$red # False value
fi
printf "${yellow}%-20s${reset} : ${color}%s${reset}\n" "$key" "$value"
done
echo -e "--- ENVIRONMENT ---"
for key in "${!ENV[@]}"; do
value="${ENV[$key]}"
value="${value%"${value##*[![:space:]]}"}" # Trim trailing whitespace
value="${value#"${value%%[![:space:]]*}"}" # Trim leading whitespace
color="$reset"
if [[ $value == 'null' ]]; then
value="" # Null value
elif [[ -z $value ]]; then
# value="EMPTY" # Empty string
# color=$cyan # Empty value
:
elif [[ $value == '1' ]]; then
color=$green # True value
elif [[ $value == '0' ]]; then
color=$red # False value
fi
printf "${yellow}%-20s${reset} : ${color}%s${reset}\n" "$key" "$value"
done
echo -e "--- FILES ---"
for key in "${!FILE[@]}"; do
value="${FILE[$key]}"
value="${value%"${value##*[![:space:]]}"}" # Trim trailing whitespace
value="${value#"${value%%[![:space:]]*}"}" # Trim leading whitespace
color="$reset"
if [[ $value == 'null' ]]; then
value="" # Null value
elif [[ -z $value ]]; then
# value="EMPTY" # Empty string
# color=$cyan # Empty value
:
elif [[ $value == '1' ]]; then
color=$green # True value
elif [[ $value == '0' ]]; then
color=$red # False value
fi
printf "${yellow}%-20s${reset} : ${color}%s${reset}\n" "$key" "$value"
done
}
create_config_file() {
file="${ENV[config]}"
if [[ ! -f $file ]]; then
echo '# created by vita' > $file
ENV[message]+="No config file found, created one at $file\n"
fi
}
create_data_directory() {
dir="${ENV[data]}"
if [[ ! -d $dir ]]; then
mkdir -p $dir
ENV[message]+="No data directory found, create one at $dir\n"
fi
}
handle_argless_run() {
# if no arg provided, get help
if [[ -z "${ARG[input]}" ]]; then
ENV[argless]=1
#ARG[help]=1
echo -e "
Commands:
help Display help information for commands and subcommands.
quest Manage job offers and applications.
cv Manage resumes (including the master CV) and filtered YAML resumes.
render Render a YAML resume to PDF.
template Manage resume templates.
doc Manage supporting documents.
config Manage global settings and preferences.
stats Display statistics about job applications, resumes, and templates.
"
fi
}
# helpers
set_env() { echo "${ENV[$1]}"; }
get_file() { echo "${FILE[$1]}"; }
get_error_msg() { echo "${ERROR[$1]}"; }
is_null() { [[ "$1" == 'null' ]]; }
is_true() { [[ $1 -eq 1 ]]; }
is_false() { [[ $1 -eq 0 ]]; }
not() { [[ -z "$1" ]] }
# is_null() { [[ "$1" == 'null' ]] && return 0 || return 1 ; } # deprecated
# is_true() { [[ "$1" -eq 1 ]] && return 0 || return 1 ; } # deprecated
# helpers
main "$@"