Skip to content

Commit

Permalink
Merge pull request #9 from Mr-Sunglasses/minor-bug-fix
Browse files Browse the repository at this point in the history
Fix config read and errors
  • Loading branch information
Mr-Sunglasses committed Dec 12, 2023
2 parents eeaa33f + 263903e commit 89bbdb8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bitssh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
import tomli as tomllib


__version__ = "2.5.0"
__version__ = "2.6.0"
2 changes: 1 addition & 1 deletion src/bitssh/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions src/bitssh/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
43 changes: 24 additions & 19 deletions src/bitssh/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import re
import pprint


class ConfigPathUtility:
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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

0 comments on commit 89bbdb8

Please sign in to comment.