This repository was archived by the owner on Aug 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager
More file actions
executable file
·137 lines (121 loc) · 3.27 KB
/
manager
File metadata and controls
executable file
·137 lines (121 loc) · 3.27 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
#!/bin/bash
# shellcheck disable=SC1090
## Definitions
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PLIST=${DIR}/plugins/plugin.list
ELIST=${DIR}/extensions/extension.list
DEV=true
## Colors
declare -A COLOR
COLOR=(
[nc]='\033[0m'
[erro]='\033[31m'
[warn]='\033[33m'
[done]='\033[32m'
[info]='\033[34m'
)
## Output types
if ${DEV}; then
function output () {
while read LINE; do
if [[ ${LINE%% *} =~ ^erro|done|info|warn$ ]]; then
echo -e "${COLOR[${LINE%% *}]}$(date +%F\ %T\ %z) | ${LINE%% *} | ${LINE#* }${COLOR[nc]}"
else
echo -e "${COLOR[nc]}$(date +%F\ %T\ %z) | ${LINE}${COLOR[nc]}"
fi
done
}
function xt () {
echo "$1 Set return code to $2"
return "$2"
}
else
function output () {
while read LINE; do
echo -e "${COLOR[${LINE%% *}]}${LINE#* }${COLOR[nc]}"
done
}
function xt () {
return "$2"
}
fi
# Main run
function main () {
export CWDIR=${DIR}/plugins/${1}
if (containsElement "$1" "${plugins[@]}"); then
if [ "$2" = "help" ]; then
echo "info $1"
else
[ -f "${CWDIR}/.env" ] && source "${CWDIR}/.env"
source "${CWDIR}/main.sh"
fi
else
echo "erro Plugin $1 not found."
avail-plugins
echo "info Tip: If you added the plugin recently, add it to the index with '${0##*/} index'"
fi
}
function containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
function nopluginlist {
echo "warn No plugin list found. Try running '${0##*/} index' to index everything."
}
function avail-plugins {
if [ -f "${PLIST}" ]; then
echo "warn Available plugins:"
mapfile -t plugins < "${PLIST}" || echo "erro Failed to load plugin list."
echo "warn ${plugins[@]}"
else
nopluginlist
fi
}
function index {
echo "info Indexing plugins"
truncate -s 0 "${PLIST}"
for i in $(find "${DIR}"/plugins/* -type d | grep -P "(?<=\/plugins\/)([\w\d\-\_])*" -o); do
echo "$i" >> "${PLIST}" && echo "done Added plugin '$i'."
done
echo "info Indexing extensions"
truncate -s 0 "${ELIST}"
for i in $(find "${DIR}"/extensions/* -type f | grep -P "(?<=\/extensions\/)([\w\d\-\_])*(\.func)" -o); do
echo "$i" >> "${ELIST}" && echo "done Added extension '$i'."
done
}
function loadlists {
mapfile -t plugins < "${PLIST}" || echo "erro Failed to load plugin list."
mapfile -t extensions < "${ELIST}" || echo "erro Failed to load extension list."
for i in "${extensions[@]}"; do
source "${DIR}/extensions/$i" || echo "warn Failed to import extension ${i}."
done
}
function preparedirs {
if mkdir "${DIR}"/plugins/ "${DIR}"/extensions/; then
echo "info Created a empty plugins and extensions directory."
else
echo "erro Could not create directory."
fi
}
## Main run
(
[ ${DEV} = "true" ] && echo "warn Running in development mode!"
if ! [ $# -eq 0 ] && ! [[ "$1" = "index" ]] && [ -f "${PLIST}" ] && [ -f "${ELIST}" ]; then
loadlists
main "$@"
elif [ -d "${DIR}"/plugins/ ] && [ -d "${DIR}"/extensions/ ]; then
if [ $# -eq 0 ]; then
echo "warn Nothing to do!"
avail-plugins
elif [[ "$1" = "index" ]]; then
index
else
nopluginlist
fi
else
preparedirs
fi
! [[ "$1" = "rawpl" ]] && echo "info Made with ♥ by casKd | t.me/casKd_dev"
) | output