forked from Worldie-com/pen.el
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcterm
More file actions
executable file
·160 lines (127 loc) · 2.35 KB
/
cterm
File metadata and controls
executable file
·160 lines (127 loc) · 2.35 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
#!/bin/bash
export TTY
# cterm/pet
# Version 1.0, bash
# Examples:
# ct vim /
if ! docker-running-p; then
echo "Pen docker container not running" 1>&2
"$@"
fi
stdin_exists() {
! [ -t 0 ] && ! test "$(readlink /proc/$$/fd/0)" = /dev/null
}
if stdin_exists; then
# In order to make this also work on the host, the temporary file must go into the ~/.pen directory
input_fp="$(cat | pen-tf txt)"
fi
exec <&1
sn="$(basename "$0")"
cterm-logo 1>&2
{
echo -n Running
echo -n " $(cmd-nice-posix "$@") " | pen-hls red
echo in cterm
} 1>&2
while [ $# -gt 0 ]; do opt="$1"; case "$opt" in
-E) {
DO_EXEC=y
shift
}
;;
-termxt) {
export USE_TERM=xterm-256color
shift
}
;;
-tm) {
export USE_TMUX=y
shift
}
;;
-nv) {
export USE_NVC=y
shift
}
;;
-e) {
extra_elisp="$2"
shift
shift
}
;;
*) break;
esac; done
if test "$#" -eq 0; then
set -- bash
fi
if test "$DO_EXEC" = "y"; then
CMD="$1"
else
CMD="$(cmd-nice-posix "$@")"
fi
USE_TMUX=y
case "$CMD" in
zsh|"\"zsh"\"|vd*) {
USE_TMUX=y
}
;;
*)
esac
if test "$USE_TMUX" = "y"; then
# tmmaybe=(tmwr)
CMD="tmwr $CMD"
set -- tmwr "$@"
fi
inside-docker-p() {
test -f /.dockerenv
}
SSH_TO_HOST=y
case "$sn" in
*cterm|ct*) {
SSH_TO_HOST=y
}
;;
# pen eterm
pet|*eterm|et*) {
SSH_TO_HOST=n
}
;;
*)
esac
if inside-docker-p; then
: ${CWD:="$(pwd)"}
else
: ${CWD:="$(pwd)"}
# CWD=/
fi
if inside-docker-p; then
if test -n ~/pen_user.txt; then
PEN_USER="$(cat ~/pen_user.txt)"
fi
: ${PEN_USER:="$(pen-readln "host username")"}
else
: ${USER:="$(whoami)"}
PEN_USER=$USER
fi
# These don't get through the interop
export SSH_TO_HOST
export CWD
export CMD
export PEN_USER
# So use cli args instead
bufname="cterm-$(printf -- "%s " "$CMD" | slugify | cut -c 1-30 | sed -e 's/^-//' -e 's/-$//')"
if test -n "$input_fp"; then
CMD="cat $(cmd-nice-posix "$input_fp") | $CMD"
fi
# This runs in the docker to the host
# The "$@" are unneccesary because of CMD exported
cterm-docker \
-bufname "$bufname" \
-e "$extra_elisp" \
pen-cterm-ssh \
-ssh-to-host "$SSH_TO_HOST" \
-cwd "$CWD" \
-cmd "$CMD" \
-user "$PEN_USER" \
"$@"