ibrokemycomputer / gnome-shell-extension-ssh-quick-connect

Adds launchers for all items in your ssh config file to a dropdown in the panel.
11 stars 8 forks source link

Filter out hosts with wildcards/ separate multi-line entries #16

Open knotguy164 opened 1 year ago

knotguy164 commented 1 year ago

ssh.config 'Host' line allows Multiple space-separated entries, and wildcards. Neither works with ssh command. I suggest splitting each Host line, and filtering out any entry with a wildcard. I have done limited testing with the following minimal change to the parseHosts function, and it appears to work (I am not proficient in javaScript, so there is likely a better way to do it):

/**
   * 
   * @param {String} sshConfig The ssh config file to parse
   * @returns {Array} An array of hosts
   */
  parseHosts(sshConfig) {
    var ret = []
    var allHostLines = sshConfig
          .split('\n')
          .join('{{NEWLINE}}')
          .split('\r')
          .join('{{NEWLINE}}')
          .split('{{NEWLINE}}')
          .map(item => item.trim())
          .filter(item => item.indexOf('Host ') === 0)
          .map(item => item = item.split('Host ')[1]);
    allHostLines.forEach(hostLine => {
        // need to replace multiple spaces with single speces to the split doesn't have null entries
        hostLine.replace(/\s\s+/g, " ").split(" ").forEach(hostStr => {
            if (!["*","?"].some(v => hostStr.includes(v))) {
                ret.push(hostStr)
            }
        });
    });
    return ret;
  }