diff --git a/example/ch08/drop b/example/ch08/drop new file mode 120000 index 0000000..9107510 --- /dev/null +++ b/example/ch08/drop @@ -0,0 +1 @@ +drop.pl \ No newline at end of file diff --git a/example/ch08/drop.pl b/example/ch08/drop.pl new file mode 100755 index 0000000..5f2023f --- /dev/null +++ b/example/ch08/drop.pl @@ -0,0 +1,11 @@ +#! /usr/bin/env perl +# 从 vim 内置终端发送 drop 消息打开文件 +# 传输的 json 消息必须用双引号 "" +use strict; +use warnings; + +use Cwd 'abs_path'; +my $filename = shift or die "usage: dorp filename"; +my $filepath = abs_path($filename); +exec "vim $filepath" unless $ENV{VIM}; +print qq{\x1B]51;["drop", "$filepath"]\x07}; diff --git a/example/ch08/drop.py b/example/ch08/drop.py new file mode 100755 index 0000000..2f08937 --- /dev/null +++ b/example/ch08/drop.py @@ -0,0 +1,7 @@ +#! /usr/bin/env python +import sys, os +if len(sys.argv) > 1: + fn = os.path.abspath(sys.argv[1]) + sys.stdout.write('\x1b]51;["drop", "%s"]\x07'%fn) + +# https://www.zhihu.com/question/278228687/answer/413375553 diff --git a/example/ch08/drop.sh b/example/ch08/drop.sh new file mode 100755 index 0000000..c7f6190 --- /dev/null +++ b/example/ch08/drop.sh @@ -0,0 +1,4 @@ +#! /bin/bash + +# echo -e '\e]51;["drop", "$1"]\x07' +echo -e "\e]51;[\"drop\", \"$1\"]\x07"