Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants