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

Possibility of Decode also reading into root Include #30

Open
Lilja opened this issue Apr 8, 2021 · 1 comment
Open

Possibility of Decode also reading into root Include #30

Lilja opened this issue Apr 8, 2021 · 1 comment

Comments

@Lilja
Copy link

Lilja commented Apr 8, 2021

I'm working on a tool that reads into the ssh config and uses FZF to be able to sort these, with enter and you should SSH to that host. I'm currently rewriting it from python to go(i'm a go beginner) and I saw your project so I thought it would fit well.

In my ssh config I have the following structure.

# ~/.ssh/config
Include ~/dotfiles/ssh/config

Host *
  AddKeysToAgent yes

And in ~/dotfiles/ssh/config I have a bunch of Hosts defined.

Now, the problem is that these are not listed when I'm using ssh_config.Decode(). Only the root ones. This is a problem for me as I neccesarily know what my hosts are named. So by iterating I get nothing of it.

The way for me as I try to work around this issue is to somehow maybe regex my way out of it and keep multiple cfg instances. Python-pseudo code like:

def get_all_hosts(path = null, hosts = []) -> Host:
    if not path:
        _file = os.Path("~", ".ssh", "config")
    else:
        _file = os.Path(path)

    with open(_file, 'r') as o:
        x = o.read()
        matches = x.match(r"^Include (\W*)")
        if matches:
            return recursive(matches, hosts)
        else:
            cfg = ssh_config.Decode(_file)
            return hosts + cfg.hosts # Concat all hosts with leaf host

(I haven't implemeted this or something similar, just prototyping).

I previously used Storm, they implemented Include like this

It would be awesome if Decode would also be able to recursivly get these as well. Either opt-in with some sort of boolean flag or natively.

@virtuald
Copy link
Contributor

virtuald commented Apr 8, 2021

The UserSettings object implements this sort of cascading configuration retrieval, but you can't control which files it reads from IIRC. Maybe if it were made more general then you could use that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants