Skip to content
This repository has been archived by the owner on Feb 9, 2025. It is now read-only.

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

Open
knotguy164 opened this issue Mar 3, 2023 · 0 comments
Open

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

knotguy164 opened this issue Mar 3, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@knotguy164
Copy link

knotguy164 commented Mar 3, 2023

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;
  }
@ibrokemycomputer ibrokemycomputer self-assigned this Apr 29, 2023
@ibrokemycomputer ibrokemycomputer added enhancement New feature or request help wanted Extra attention is needed labels Nov 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants