forked from Worldie-com/pen.el
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheval.sh
More file actions
executable file
·126 lines (97 loc) · 3.6 KB
/
eval.sh
File metadata and controls
executable file
·126 lines (97 loc) · 3.6 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
#!/bin/bash
export PS4='+ "$(basename $0)" ${LINENO} '
sn="$(basename "$0")"
if test -f $HOME/.emacs.d/host/pen.el/scripts/$sn && ! test "$HOME/.emacs.d/host/pen.el/scripts" = "$(dirname "$0")"; then
~/.emacs.d/host/pen.el/scripts/$sn "$@"
exit "$?"
fi
{
stty stop undef; stty start undef
} 2>/dev/null
exec 0</dev/null
# set -xv
# Debian10 run Pen
# export PEN_DEBUG=y
export LANG=en_US
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8
: "${SOCKET:="DEFAULT"}"
while [ $# -gt 0 ]; do opt="$1"; case "$opt" in
"") { shift; }; ;;
-D) {
SOCKET="$2"
shift
shift
}
;;
-nto) {
PEN_NO_TIMEOUT=y
shift
}
;;
--parallel|--pool) {
export USE_POOL=y
shift
}
;;
*) break;
esac; done
export EMACSD=/root/.emacs.d
export YAMLMOD_PATH=$EMACSD/emacs-yamlmod
export PATH=$PATH:$EMACSD/host/pen.el/scripts:$EMACSD/pen.el/scripts::$EMACSD/host/pen.el/scripts/container:$EMACSD/pen.el/scripts/container
last_arg="${@: -1}"
last_arg="$(p "$last_arg" | pen-str unonelineify-safe)"
# last_arg="$(p "$last_arg" | pen-bs '\\')"
# echo "$last_arg" > /tmp/yo.txt
shopt -s nullglob
if test "$USE_POOL" = "y"; then
# ugh... using sentinels is a pain. Just select one.
# Just take the first one
# SOCKET="$(basename "$(shopt -s nullglob; cd $HOME/.pen/pool/available; ls pen-emacsd-* | shuf -n 1)")"
mkdir -p ~/.pen/pool/available
for socket_fp in ~/.pen/pool/available/pen-emacsd-*; do
SOCKET="$(basename "$socket_fp")"
echo "$SOCKET" >> /tmp/d.txt
break
done
test -z "$SOCKET" && exit 1
test "$SOCKET" = DEFAULT && exit 1
rm -f ~/.pen/pool/available/$SOCKET
fi
# Can't use a timestamp because I might want to try eval.sh again
# prompt_id="$(cmd "$@" | sha1sum | awk '{print $1}')"
# Add the date so never any collisions
# fp="/tmp/eval-output-${SOCKET}-$prompt_id.txt"
# fp="/tmp/eval-output-${SOCKET}-$prompt_id.txt"
# This is not the place to memoise with prompt sha
fp="/tmp/eval-output-${SOCKET}-$(uuid || :).txt"
if ! test -s "$fp"; then
rm -f "$fp"
fi
# Consider using timeout here
# Part of the reason there is a timeout is that the engines used may be unknown by the prompter, due to the shell interop.
# The human engine should have executive power though to prevent the timeout.
# The omission is made here:
# vim +/"# No timeout for human engine" "$HOME/source/git/semiosis/pen.el/scripts/lm-complete-generic"
# So at this point, we simply have a timeout which we can disable if we want.
# The bash interop isn't normally *supposed* to use the human engine, so, this is ok to keep it as default here.
sentinel_string="tm_sentinel_${RANDOM}_$$"
# unbuffer pen-emacsclient -a "" -s ~/.emacs.d/server/$SOCKET -e "(pen-eval-for-host \"$fp\" \"~/.pen/pool/available/$SOCKET\" $last_arg)"
tmux neww -d -n eval-ec-$SOCKET "PEN_NO_TIMEOUT=$PEN_NO_TIMEOUT $(cmd pen-timeout 10 unbuffer pen-emacsclient -a "" -s ~/.emacs.d/server/$SOCKET -e "(pen-eval-for-host \"$fp\" \"~/.pen/pool/available/$SOCKET\" $last_arg)"); tmux wait-for -S '$sentinel_string';"
tmux wait-for "$sentinel_string"
export SOCKET
export USE_POOL
# Can't remove this sleep yet.
# Do this to test.
# cd "$NOTES"; penf -u pf-very-witty-pick-up-lines-for-a-topic/1 imagination
sleep 0.1
# I need to hide the fact that it failed. Otherwise, I can't cancel comint commands without polluting the repl
if test -s "$fp"; then
0</dev/null cat "$fp" 2>/dev/null
fi
# touch ~/.pen/pool/available/$SOCKET
# sleep 1
# nohup pen-fix-daemon $SOCKET
if test "$USE_POOL" = "y"; then
tmux neww -d -n fix-$SOCKET "shx pen-fix-daemon $SOCKET"
fi