@@ -268,6 +268,10 @@ int main(int argc, char **argv)
268
268
}
269
269
270
270
server_init(params.listen_addr);
271
+
if (params.remote) {
272
+
handle_remote_client(¶ms, params.remote,
273
+
params.server_addr, argc, argv);
274
+
}
271
275
272
276
if (GARGCOUNT > 0) {
273
277
fname = get_fname(¶ms, cwd);
@@ -803,6 +807,67 @@ static void init_locale(void)
803
807
}
804
808
#endif
805
809
810
+
/// Handle remote subcommands
811
+
static void handle_remote_client(mparm_T *params, int remote_args,
812
+
char *server_addr, int argc, char **argv)
813
+
{
814
+
Object rvobj = OBJECT_INIT;
815
+
rvobj.data.dictionary = (Dictionary)ARRAY_DICT_INIT;
816
+
rvobj.type = kObjectTypeDictionary;
817
+
CallbackReader on_data = CALLBACK_READER_INIT;
818
+
const char *error = NULL;
819
+
uint64_t rc_id = server_addr == NULL ? 0 : channel_connect(false,
820
+
server_addr, true, on_data, 50, &error);
821
+
822
+
Boolean should_exit = true;
823
+
Boolean tabbed;
824
+
int files;
825
+
826
+
int t_argc = remote_args;
827
+
Array args = ARRAY_DICT_INIT;
828
+
String arg_s;
829
+
for (; t_argc < argc; t_argc++) {
830
+
arg_s = cstr_to_string(argv[t_argc]);
831
+
ADD(args, STRING_OBJ(arg_s));
832
+
}
833
+
834
+
Error err = ERROR_INIT;
835
+
Array a = ARRAY_DICT_INIT;
836
+
ADD(a, INTEGER_OBJ((int)rc_id));
837
+
ADD(a, ARRAY_OBJ(args));
838
+
String s = cstr_to_string("return vim._cs_remote(...)");
839
+
Object o = executor_exec_lua_api(s, a, &err);
840
+
api_free_string(s);
841
+
api_free_array(a);
842
+
843
+
if (o.type == kObjectTypeDictionary) {
844
+
rvobj.data.dictionary = o.data.dictionary;
845
+
} else if (!ERROR_SET(&err)) {
846
+
api_set_error(&err, kErrorTypeException,
847
+
"Function returned unexpected value");
848
+
}
849
+
850
+
for (size_t i = 0; i < rvobj.data.dictionary.size ; i++) {
851
+
if (strcmp(rvobj.data.dictionary.items[i].key.data, "tabbed") == 0) {
852
+
// should we check items[i].value.type here?
853
+
tabbed = rvobj.data.dictionary.items[i].value.data.boolean;
854
+
} else if (strcmp(rvobj.data.dictionary.items[i].key.data, "should_exit") == 0) {
855
+
should_exit = rvobj.data.dictionary.items[i].value.data.boolean;
856
+
} else if (strcmp(rvobj.data.dictionary.items[i].key.data, "files") == 0) {
857
+
files = (int)rvobj.data.dictionary.items[i].value.data.integer;
858
+
}
859
+
}
860
+
861
+
if (should_exit) {
862
+
mch_exit(0);
863
+
} else {
864
+
if (tabbed) {
865
+
params->window_count = files;
866
+
params->window_layout = WIN_TABS;
867
+
}
868
+
}
869
+
}
870
+
806
871
/// Decides whether text (as opposed to commands) will be read from stdin.
807
872
/// @see EDIT_STDIN
808
873
static bool edit_stdin(bool explicit, mparm_T *parmp)
@@ -868,6 +933,8 @@ static void command_line_scan(mparm_T *parmp)
868
933
// "--version" give version message
869
934
// "--noplugin[s]" skip plugins
870
935
// "--cmd <cmd>" execute cmd before vimrc
936
+
// "--remote" execute commands remotey on a server
937
+
// "--server" name of vim server to send remote commands to
871
938
if (STRICMP(argv[0] + argv_idx, "help") == 0) {
872
939
usage();
873
940
os_exit(0);
@@ -906,6 +973,11 @@ static void command_line_scan(mparm_T *parmp)
906
973
argv_idx += 6;
907
974
} else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) {
908
975
// Do nothing: file args are always literal. #7679
976
+
} else if (STRNICMP(argv[0] + argv_idx, "remote", 6) == 0) {
977
+
parmp->remote = parmp->argc - argc;
978
+
} else if (STRNICMP(argv[0] + argv_idx, "server", 6) == 0) {
979
+
want_argument = true;
980
+
argv_idx += 6;
909
981
} else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) {
910
982
p_lpl = false;
911
983
} else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) {
@@ -1137,6 +1209,9 @@ static void command_line_scan(mparm_T *parmp)
1137
1209
} else if (strequal(argv[-1], "--listen")) {
1138
1210
// "--listen {address}"
1139
1211
parmp->listen_addr = argv[0];
1212
+
} else if (strequal(argv[-1], "--server")) {
1213
+
// "--server {address}"
1214
+
parmp->server_addr = argv[0];
1140
1215
}
1141
1216
// "--startuptime <file>" already handled
1142
1217
break;
@@ -1291,6 +1366,8 @@ static void init_params(mparm_T *paramp, int argc, char **argv)
1291
1366
paramp->use_debug_break_level = -1;
1292
1367
paramp->window_count = -1;
1293
1368
paramp->listen_addr = NULL;
1369
+
paramp->server_addr = NULL;
1370
+
paramp->remote = 0;
1294
1371
}
1295
1372
1296
1373
/// Initialize global startuptime file if "--startuptime" passed as an argument.
@@ -2041,6 +2118,8 @@ static void usage(void)
2041
2118
mch_msg(_(" --headless Don't start a user interface\n"));
2042
2119
mch_msg(_(" --listen <address> Serve RPC API from this address\n"));
2043
2120
mch_msg(_(" --noplugin Don't load plugins\n"));
2121
+
mch_msg(_(" --remote[-subcommand] Execute commands remotely on a server\n"));
2122
+
mch_msg(_(" --server <address> Specify RPC server to send commands to\n"));
2044
2123
mch_msg(_(" --startuptime <file> Write startup timing messages to <file>\n"));
2045
2124
mch_msg(_("\nSee \":help startup-options\" for all options.\n"));
2046
2125
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4