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
|
--- kbfunc.c.orig 2021-07-28 22:35:08 UTC
+++ kbfunc.c
@@ -753,6 +753,72 @@ out:
}
void
+kbfunc_menu_mosh(void *ctx, struct cargs *cargs)
+{
+ struct screen_ctx *sc = ctx;
+ struct cmd_ctx *cmd;
+ struct menu *mi;
+ struct menu_q menuq;
+ FILE *fp;
+ char *buf, *lbuf, *p;
+ char hostbuf[_POSIX_HOST_NAME_MAX+1];
+ char path[PATH_MAX];
+ int l;
+ size_t len;
+ ssize_t slen;
+ int mflags = (CWM_MENU_DUMMY);
+
+ TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
+ if (strcmp(cmd->name, "term") == 0)
+ break;
+ }
+ TAILQ_INIT(&menuq);
+
+ if ((fp = fopen(Conf.known_hosts, "r")) == NULL) {
+ warn("%s: %s", __func__, Conf.known_hosts);
+ goto menu;
+ }
+
+ lbuf = NULL;
+ len = 0;
+ while ((slen = getline(&lbuf, &len, fp)) != -1) {
+ buf = lbuf;
+ if (buf[slen - 1] == '\n')
+ buf[slen - 1] = '\0';
+
+ /* skip hashed hosts */
+ if (strncmp(buf, HASH_MARKER, strlen(HASH_MARKER)) == 0)
+ continue;
+ for (p = buf; *p != ',' && *p != ' ' && p != buf + slen; p++)
+ ;
+ /* ignore badness */
+ if (p - buf + 1 > sizeof(hostbuf))
+ continue;
+ (void)strlcpy(hostbuf, buf, p - buf + 1);
+ menuq_add(&menuq, NULL, "%s", hostbuf);
+ }
+ free(lbuf);
+ if (ferror(fp))
+ err(1, "%s", path);
+ (void)fclose(fp);
+menu:
+ if ((mi = menu_filter(sc, &menuq, "mosh", NULL, mflags,
+ search_match_text, search_print_text)) != NULL) {
+ if (mi->text[0] == '\0')
+ goto out;
+ l = snprintf(path, sizeof(path), "%s -T '[ssh] %s' -e mosh %s",
+ cmd->path, mi->text, mi->text);
+ if (l == -1 || l >= sizeof(path))
+ goto out;
+ u_spawn(path);
+ }
+out:
+ if (mi != NULL && mi->dummy)
+ free(mi);
+ menuq_clear(&menuq);
+}
+
+void
kbfunc_client_menu_label(void *ctx, struct cargs *cargs)
{
struct client_ctx *cc = ctx;
|