diff --git a/pyproject.toml b/pyproject.toml index 62bc7f0..f66c646 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "bitssh" -version = "2.5.0" +version = "2.6.0" description = "A command-line tool for managing SSH connections" readme = "README.md" authors = [{ name = "Kanishk Pachauri", email = "itskanishkp.py@gmail.com" }] @@ -32,7 +32,7 @@ Docs = "https://github.com/Mr-Sunglasses/bitssh/blob/master/docs/docs.md" bitssh = "bitssh.__main__:main" [tool.bumpver] -current_version = "2.5.0" +current_version = "2.6.0" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true diff --git a/src/bitssh/__init__.py b/src/bitssh/__init__.py index 95b247d..54780dd 100644 --- a/src/bitssh/__init__.py +++ b/src/bitssh/__init__.py @@ -7,4 +7,4 @@ import tomli as tomllib -__version__ = "2.5.0" +__version__ = "2.6.0" diff --git a/src/bitssh/prompt.py b/src/bitssh/prompt.py index 62f3791..00b9031 100644 --- a/src/bitssh/prompt.py +++ b/src/bitssh/prompt.py @@ -23,7 +23,7 @@ def ask_host_prompt(cls): cmd = cmd[6::] cmd = f"ssh {cmd}" UI.console.print( - "Please Wait While Your System is Connecting to the Remote Server", + "Please Wait While Your System is Connecting to the Remote Server 🖥️", style="green", ) os.system(cmd) diff --git a/src/bitssh/ui.py b/src/bitssh/ui.py index fb19384..275247a 100644 --- a/src/bitssh/ui.py +++ b/src/bitssh/ui.py @@ -8,8 +8,9 @@ class UI: @classmethod def draw_table(cls): - table = Table(title="SSH Servers in Config File") - table.add_column("Hostname", justify="left", style="cyan", no_wrap=True) + table = Table(title="SSH Servers in Config File 📁") + table.add_column("Hostname", justify="left", + style="cyan", no_wrap=True) table.add_column("Host", style="magenta") table.add_column("Port", justify="right", style="green") table.add_column("User", justify="right", style="yellow") diff --git a/src/bitssh/utils.py b/src/bitssh/utils.py index 5514596..1a96a7b 100644 --- a/src/bitssh/utils.py +++ b/src/bitssh/utils.py @@ -1,6 +1,5 @@ import os import re -import pprint class ConfigPathUtility: @@ -12,26 +11,31 @@ class ConfigPathUtility: @classmethod def get_config_content(cls): - config = {} - current_host = None with open(cls.config_file_path, "r") as f: - lines = f.readlines() - - for line in lines: - line = line.strip() - - if re.match(r"^Host\s+", line): - current_host = re.sub(r"^Host\s+", "", line) - config[current_host] = {} + lines = f.read() + + host_pattern = re.compile(r"Host\s+(\w+)", re.MULTILINE) + hostname_pattern = re.compile( + r"(?:HostName|Hostname)\s+(\S+)", re.MULTILINE) + user_pattern = re.compile(r"User\s+(\S+)", re.MULTILINE) + host_dict = {} + for match in host_pattern.finditer(lines): + host = match.group(1) + hostname_match = hostname_pattern.search(lines, match.end()) + if hostname_match: + hostname = hostname_match.group(1) else: - match = re.match(r"^\s*([\w-]+)\s+(.*)", line) - if match: - key = match.group(1) - value = match.group(2) - config[current_host][key] = value + hostname = host + user = user_pattern.search(lines, match.end()) + if user: + user = user.group(1) + host_dict[host] = { + "Hostname": hostname, + "User": user, + } - return config + return host_dict @classmethod def get_config_file_row_data(cls): @@ -40,7 +44,8 @@ def get_config_file_row_data(cls): ROWS = [] for host, attributes in config_content.items(): - row = (attributes["Hostname"], host, attributes["port"], attributes["User"]) + row = (attributes["Hostname"], host, + '22', attributes["User"]) ROWS.append(row) return ROWS @@ -49,5 +54,5 @@ def get_config_file_row_data(cls): def get_config_file_host_data(cls): HOST = [] for hosts in cls.get_config_file_row_data(): - HOST.append(f"Host: {hosts[1]}") + HOST.append(f"🖥️ -> {hosts[1]}") return HOST