This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
evalcmd
executable file
·89 lines (76 loc) · 2.18 KB
/
evalcmd
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
#!/usr/bin/env bash
processHooks() {
if [[ -f manpages && $2 = "man "[![:blank:]]* ]]; then
local cmd args manpages
read -r cmd args <<< "$2"
source ./manpages &&
if [[ ${manpages[$args]} ]]; then
printf '%s: %s\n' "$2" "${manpages[$args]}"
exit
fi
elif [[ -f helppages && $2 = "help "[![:blank:]]* ]]; then
local cmd args helppages
read -r cmd args <<< "$2"
source ./helppages &&
if [[ ${helppages[$args]} ]]; then
printf '%s\n' "${helppages[$args]}"
exit
fi
elif [[ $2 = trigger?(s) ]]; then
printf 'Available triggers: '
local x limit=5 idx v
for idx in "${indices[@]}"; do
v=${versions[$idx]} x=0
while [[ $v = *\# ]] && (( x++ < limit )); do
v=${versions[$v]}
done
printf '%s %s; ' "$idx" "$v"
done
exit
fi
}
if [[ $1 = -n ]]; then
nopaste=1
shift
fi
t=$1\#
declare -A triggers='()' versions='()'
indices=()
while IFS=$'\t' read -r trigger shell version; do
triggers[$trigger]=$shell
versions[$trigger]=$version
indices+=("$trigger") # to keep the order
done < ./triggers
[[ ${triggers[$t]} ]] || exit
processHooks "$@"
output=$(./limitcmd.pl "${triggers[$t]}" "$2" | expand | head -c 4242 | tr -d '\r' |
awk '{ do { print substr($0, 1, 120) (length > 120 ? "\\" : ""); $0 = substr($0, 121); } while(length($0)>0); }'; exit "${PIPESTATUS[0]}"; )
# print a \ at the end of the line if it's too long
result=$?
lines=$(wc -l <<< "$output")
shopt -s extglob
if [[ $output == *( ) ]]
then
if (( result > 0 ))
then
echo "no output within the time limit"
else
echo "no output"
fi
exit 0
fi
if ((nopaste)); then
printf '%s\n' "$output"
else
if (( lines <= 3 )); then
printf '%s\n' "$output";
exit 0
fi
if url=$(curl -sfF 'f:1=<-' http://ix.io <<< "$output"); then
etc="etc... ( $url )"
else
etc="and so forth... (but now the pastebin is sick of me)"
fi
printf '%s\n' "$output" | head -n 2
printf '%s\n' "$etc"
fi