-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
79 lines (65 loc) · 1.87 KB
/
utils.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
#!/bin/bash
debugLevel=0
logDebug() {
if [[ ${debugLevel} -ge 1 ]]; then
echo -e "\e[90mDBG: ${FUNCNAME[1]}(): ${*}\e[0m"
fi
}
logInfo() {
echo -e "INF: ${FUNCNAME[1]}(): ${*}"
}
logError() {
echo -e "\e[1;31mERR: ${FUNCNAME[1]}(): ${*}\e[0m"
}
checkAuthTokens() {
local -r config_dir="${XDG_CONFIG_HOME:-${HOME}/.config}"
local -r auth_tokens_file="${config_dir}/lfmedit/auth_tokens"
if [[ -r "${auth_tokens_file}" ]]; then
logDebug "reading authentication tokens from ${auth_tokens_file}"
# shellcheck disable=SC1090
source "${auth_tokens_file}"
else
logDebug "failed to read ${auth_tokens_file}"
fi
if [[ -z "${lastfm_username}" ]]; then
logError "last.fm username not provided, exiting!"
return 1
elif [[ -z "${lastfm_session_id}" ]]; then
logError "last.fm session ID is not provided, exiting!"
return 2
elif [[ -z "${lastfm_csrf}" ]]; then
logError "last.fm CSRF token is not provided, exiting!"
return 3
fi
logDebug "all necessary authentication tokens are set"
}
requestConfirmation() {
if [[ -v dryRun && "${dryRun}" == "yes" ]]; then
logInfo "Dry run: changes are not applied."
return 2
fi
if [[ ! -v dontAsk || "${dontAsk}" != "yes" ]]; then
read -u 1 -p "Proceed? (uppercase Y to confirm, anything else to abort): " -n 1 -r
if [[ ! ${REPLY} =~ ^Y$ ]]; then
echo
logInfo "Not applying this edit."
return 1
fi
echo
fi
}
pauseEditing() {
local -r seconds="${1}"
echo -ne "INF: Waiting ${seconds} seconds... "
for (( i=0; i<seconds; i++ )); do
echo -ne "\b|"
sleep 0.25
echo -ne "\b/"
sleep 0.25
echo -ne "\b-"
sleep 0.25
echo -ne "\b\\"
sleep 0.25
done
echo
}