forked from Worldie-com/pen.el
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathguru
More file actions
executable file
·173 lines (140 loc) · 3.42 KB
/
guru
File metadata and controls
executable file
·173 lines (140 loc) · 3.42 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
#!/bin/bash
export TTY
sn="$(basename "$0")"
inside-docker-p() {
test -f /.dockerenv
}
if inside-docker-p; then
if ! inside-tmux-p; then
# I must also cat into in-tm
# Make a new command for this purpose (capture stdin and send to container, then pipe into a new command)
stdincapture in-tm stdininject "$0" "$@"
exit "$?"
fi
fi
# Guru
# Version 1.0, bash
FRAMETYPE=tty
guru-logo Guru 1>&2
while [ $# -gt 0 ]; do opt="$1"; case "$opt" in
"") { shift; }; ;;
-nv) {
USE_NVC=y
shift
}
;;
-human|-talk-to-human) {
PEN_ENGINE=Human
shift
}
;;
-engine) {
PEN_ENGINE="$2"
shift
shift
}
;;
-temp|-temperature) {
export PEN_TEMPERATURE="$2"
shift
shift
}
;;
-tty|-nw|-t) {
export PEN_USE_GUI=n
FRAMETYPE=tty
shift
}
;;
-context) {
context="$2"
shift
shift
}
;;
-subject) {
subject="$2"
shift
shift
}
;;
-win) {
context="$(pen-tm cap-pane -nohist)"
shift
}
;;
-sps) {
do_split=y
shift
}
;;
-gui) {
export PEN_USE_GUI=y
FRAMETYPE=gui
shift
}
;;
*) break;
esac; done
if test "$do_split" = "y"; then
if test -n "$context"; then
pen-sps $0 -context "$context"
else
pen-sps $0
fi
exit "$?"
fi
export USE_NVC
export PEN_UPDATE
export PEN_ENGINE
PEN_ENGINE_ELISP="$PEN_ENGINE"
if test "$PEN_ENGINE" = nil; then
PEN_ENGINE_ELISP=nil
elif test -n "$PEN_ENGINE"; then
PEN_ENGINE_ELISP="\"$PEN_ENGINE\""
else
PEN_ENGINE_ELISP=nil
fi
stdin_exists() {
! [ -t 0 ] && ! test "$(readlink /proc/$$/fd/0)" = /dev/null
}
# test -n "$person" || {
# echo "Person name required as parameter." 12
# exit 1
# }
# if ! stdin_exists && test "$#" -eq 0; then
# person="$(pen-readln "Chatbot name")"
# else
# person="$@"
# fi
# PEN_USE_GUI is unset by design apparently
maybe_subject="$@"
if test -n "$maybe_subject"; then
subject="$maybe_subject"
fi
if stdin_exists && ! test -n "$context"; then
context="$(cat)"
exec <&1
fi
if test -n "$context"; then
if ! test -n "$subject"; then
subject="$(pen-readln "Guru Topic")"
fi
if ! test -n "$subject"; then
subject="$(echo "$context" | pen-str words 20 | penf --pool pf-get-language-1shot/1)"
fi
if test -z "$subject"; then
subject="General knowledge"
fi
# Rather than specifying directly to the prompt function,
# this value is taken up and remembered for future prompting within the apostrophe
# Perhaps I should actually not use the pool
# pen -nn -frametype "$FRAMETYPE" --pool -ic "(pen-engine $PEN_ENGINE_ELISP (progn (upd (guru $(cmd-nice-posix "$context") $(cmd-nice-posix "$subject")))(delete-other-windows)))"
pen -nn -frametype "$FRAMETYPE" -ic "(pen-engine $PEN_ENGINE_ELISP (progn (upd (guru $(cmd-nice-posix "$context") $(cmd-nice-posix "$subject")))(delete-other-windows)))"
else
if test -n "$subject"; then
pen -nn -frametype "$FRAMETYPE" -ic "(pen-engine $PEN_ENGINE_ELISP (progn (upd (guru nil $(cmd-nice-posix "$subject")))(delete-other-windows)))"
else
pen -nn -frametype "$FRAMETYPE" -ic "(pen-engine $PEN_ENGINE_ELISP (progn (upd (call-interactively 'guru))(delete-other-windows)))"
fi
fi