On 29.04., Okan Demirmen wrote:
> On Fri 2019.04.26 at 07:15 +0200, Bruno Fl?ckiger wrote:
> > Hi,
> >
> > The ssh menu of cwm(1) doesn't filter duplicated hostnames when reading
> > them from ~/.ssh/known_hosts. This patch makes sure each hostname is
> > only displayed once to the menu.
>
> Sure, maybe; but why again do we even have this inside a window manager?
> Really, the known_hosts parsing is incomplete at best; either the entire
> parsing code needs to be lifted from ssh or this (mis)feature should be
> removed from cwm. I prefer the latter.
>

After trying some possible replacements from ports it turns out that
dmenu from suckless.org together with a small shell script works best
for me.

This patch removes menu-ssh completely from cwm.

Cheers,
Bruno

Index: app/cwm/calmwm.h
===================================================================
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.371
diff -u -p -r1.371 calmwm.h
--- app/cwm/calmwm.h    7 Mar 2019 14:28:17 -0000       1.371
+++ app/cwm/calmwm.h    9 May 2019 08:22:14 -0000
@@ -304,7 +304,6 @@ struct conf {
        int                      xrandr;
        int                      xrandr_event_base;
        char                    *conf_file;
-       char                    *known_hosts;
        char                    *wm_argv;
        int                      debug;
 };
@@ -517,7 +516,6 @@ void                         kbfunc_menu_cmd(void *, struct 
c
 void                    kbfunc_menu_group(void *, struct cargs *);
 void                    kbfunc_menu_wm(void *, struct cargs *);
 void                    kbfunc_menu_exec(void *, struct cargs *);
-void                    kbfunc_menu_ssh(void *, struct cargs *);
 void                    kbfunc_client_menu_label(void *, struct cargs *);
 void                    kbfunc_exec_cmd(void *, struct cargs *);
 void                    kbfunc_exec_lock(void *, struct cargs *);
Index: app/cwm/conf.c
===================================================================
RCS file: /cvs/xenocara/app/cwm/conf.c,v
retrieving revision 1.249
diff -u -p -r1.249 conf.c
--- app/cwm/conf.c      7 Mar 2019 12:54:21 -0000       1.249
+++ app/cwm/conf.c      9 May 2019 08:22:14 -0000
@@ -179,7 +179,6 @@ static const struct {

        { FUNC_SC(menu-cmd, menu_cmd, 0) },
        { FUNC_SC(menu-group, menu_group, 0) },
-       { FUNC_SC(menu-ssh, menu_ssh, 0) },
        { FUNC_SC(menu-window, menu_client, CWM_MENU_WINDOW_ALL) },
        { FUNC_SC(menu-window-hidden, menu_client, CWM_MENU_WINDOW_HIDDEN) },
        { FUNC_SC(menu-exec, menu_exec, 0) },
@@ -210,7 +209,6 @@ static const struct {
        { "CM-Delete",  "lock" },
        { "M-question", "menu-exec" },
        { "CM-w",       "menu-exec-wm" },
-       { "M-period",   "menu-ssh" },
        { "M-Return",   "window-hide" },
        { "M-Down",     "window-lower" },
        { "M-Up",       "window-raise" },
@@ -316,7 +314,6 @@ conf_init(struct conf *c)
                        home = "/";
        }
        xasprintf(&c->conf_file, "%s/%s", home, ".cwmrc");
-       xasprintf(&c->known_hosts, "%s/%s", home, ".ssh/known_hosts");
 }

 void
@@ -363,7 +360,6 @@ conf_clear(struct conf *c)
                free(c->color[i]);

        free(c->conf_file);
-       free(c->known_hosts);
        free(c->font);
        free(c->wmname);
 }
Index: app/cwm/cwm.1
===================================================================
RCS file: /cvs/xenocara/app/cwm/cwm.1,v
retrieving revision 1.64
diff -u -p -r1.64 cwm.1
--- app/cwm/cwm.1       25 Feb 2019 18:07:48 -0000      1.64
+++ app/cwm/cwm.1       9 May 2019 08:22:14 -0000
@@ -140,15 +140,6 @@ Resize window by a large amount; see
 Spawn
 .Dq exec program
 dialog.
-.It Ic M-period
-Spawn
-.Dq ssh to
-dialog.
-This parses
-.Pa $HOME/.ssh/known_hosts
-to provide host auto-completion.
-.Xr ssh 1
-will be executed via the configured terminal emulator.
 .It Ic CM-w
 Spawn
 .Dq exec WindowManager
Index: app/cwm/cwmrc.5
===================================================================
RCS file: /cvs/xenocara/app/cwm/cwmrc.5,v
retrieving revision 1.72
diff -u -p -r1.72 cwmrc.5
--- app/cwm/cwmrc.5     25 Feb 2019 16:40:49 -0000      1.72
+++ app/cwm/cwmrc.5     9 May 2019 08:22:14 -0000
@@ -280,10 +280,6 @@ menu.
 Launch
 .Dq exec WindowManager
 menu.
-.It menu-ssh
-Launch
-.Dq ssh
-menu.
 .It group-toggle-[n]
 Toggle visibility of group n, where n is 1-9.
 .It group-only-[n]
Index: app/cwm/kbfunc.c
===================================================================
RCS file: /cvs/xenocara/app/cwm/kbfunc.c,v
retrieving revision 1.165
diff -u -p -r1.165 kbfunc.c
--- app/cwm/kbfunc.c    7 Mar 2019 14:28:17 -0000       1.165
+++ app/cwm/kbfunc.c    9 May 2019 08:22:14 -0000
@@ -644,72 +644,6 @@ out:
 }

 void
-kbfunc_menu_ssh(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[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, "ssh", 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 ssh %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;

Reply via email to