Skip to content

Commit 43a6dd3

Browse files
committed
Add tmux support to it2dl. Issue 9550
1 parent 84b85d9 commit 43a6dd3

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

utilities/it2dl

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ if [ $# -lt 1 ]; then
44
exit 1
55
fi
66

7+
# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
8+
# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
9+
# only accepts ESC backslash for ST. We use TERM instead of TMUX because TERM
10+
# gets passed through ssh.
11+
function print_osc() {
12+
if [[ $TERM == screen* || $TERM == tmux* ]]; then
13+
printf "\033Ptmux;\033\033]"
14+
else
15+
printf "\033]"
16+
fi
17+
}
18+
19+
# More of the tmux workaround described above.
20+
function print_st() {
21+
if [[ $TERM == screen* || $TERM == tmux* ]]; then
22+
printf "\a\033\\"
23+
else
24+
printf "\a"
25+
fi
26+
}
27+
728
function load_version() {
829
if [ -z ${IT2DL_BASE64_VERSION+x} ]; then
930
export IT2DL_BASE64_VERSION=$(base64 --version 2>&1)
@@ -25,11 +46,28 @@ for fn in "$@"
2546
do
2647
if [ -r "$fn" ] ; then
2748
[ -d "$fn" ] && { echo "$fn is a directory"; continue; }
28-
printf '\033]1337;File=name=%s;' $(echo -n "$fn" | b64_encode)
29-
wc -c "$fn" | awk '{printf "size=%d",$1}'
30-
printf ":"
31-
base64 < "$fn"
32-
printf '\a'
49+
if [[ $TERM == screen* || $TERM == tmux* ]]; then
50+
print_osc
51+
printf '1337;MultipartFile=name=%s;' $(echo -n "$fn" | b64_encode)
52+
wc -c "$fn" | awk '{printf "size=%d",$1}'
53+
print_st
54+
55+
parts=$(b64_encode < "$fn" | fold -w 256)
56+
for part in $parts; do
57+
print_osc
58+
printf '1337;FilePart=%s' "$part"
59+
print_st
60+
done
61+
print_osc
62+
printf '1337;FileEnd'
63+
print_st
64+
else
65+
printf '\033]1337;File=name=%s;' $(echo -n "$fn" | b64_encode)
66+
wc -c "$fn" | awk '{printf "size=%d",$1}'
67+
printf ":"
68+
base64 < "$fn"
69+
printf '\a'
70+
fi
3371
else
3472
echo File $fn does not exist or is not readable.
3573
fi

0 commit comments

Comments
 (0)