From 7293796883e4c1eadb1723470b7913463c2242f1 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sun, 26 May 2024 22:17:06 -0600 Subject: [PATCH] Parser: fix config parser --- README.md | 25 +++++++++++++++++++++---- src/ssh_config_to_yaml.py | 4 ++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f94da7a..e08db1f 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,29 @@ coronation: Hostname: coronation.cs.ualberta.ca ``` -## Rules +## Quick Start + +```bash +mv ~/.ssh/config ~/.ssh/config_og +python3 src/ssh_config_to_yaml.py ~/.ssh/config_og --out ~/.ssh/config.yaml +# Do some edits on ~/.ssh/config.yaml. The migration script won't compress +# things with for-loops or templates. Then... +python3 ~/.ssh/config.yaml --out ~/.ssh/config +``` + +As a proof of concept, you can even chain the scripts! The order of hosts will +change, but the config should function identically! + +```bash +python3 src/main.py <(python3 src/ssh_config_to_yaml.py ~/.ssh/config) +``` + +# Rules The `src/ssh_config_to_yaml.py` script will assist in quickly migrating your existing config. -#### SSH Properties +### SSH Properties Standard SSH config properties go under the `ssh_props` heading for every host. For example: @@ -72,7 +89,7 @@ github.com: Note that yaml does not support duplicate keys, so keys can take a list of properties instead to mimic repeated keys, as seen above. -#### Templates +### Templates Templates are "default" properties inherited from another host. Templates must be declared above the host that uses it. You can make a template-only host by @@ -153,7 +170,7 @@ Host ohaton LocalForward 9000 localhost:9000 ``` -#### For loops +### For loops For loops allow simple substitution of a single variable over a range or set of values. Ranges must be numerical, but sets can be any arbitrary string. Multiple diff --git a/src/ssh_config_to_yaml.py b/src/ssh_config_to_yaml.py index 121bd78..d85d66d 100644 --- a/src/ssh_config_to_yaml.py +++ b/src/ssh_config_to_yaml.py @@ -26,7 +26,7 @@ def parse_sshconfig(lines): if m_host: if hostname is not None: - parse[hostname] = host + parse[hostname] = { "ssh_props": host } hostname = m_host[1] host = dict() @@ -36,7 +36,7 @@ def parse_sshconfig(lines): host[m_prop[1]] = [m_prop[2]] if hostname is not None: - parse[hostname] = host + parse[hostname] = { "ssh_props": host } return parse