@@ -4,6 +4,27 @@ if [ $# -lt 1 ]; then
4
4
exit 1
5
5
fi
6
6
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
+
7
28
function load_version() {
8
29
if [ -z ${IT2DL_BASE64_VERSION+x} ]; then
9
30
export IT2DL_BASE64_VERSION=$( base64 --version 2>&1 )
@@ -25,11 +46,28 @@ for fn in "$@"
25
46
do
26
47
if [ -r " $fn " ] ; then
27
48
[ -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
33
71
else
34
72
echo File $fn does not exist or is not readable.
35
73
fi
0 commit comments