feat: update SSH login retrieval in hello.py and improve logo display logic in functions.py
Some checks failed
Nix Format Check / check-format (push) Failing after 37s

This commit is contained in:
2025-03-10 19:13:21 +01:00
parent 3e9e83e25d
commit 7afd1f0bca
2 changed files with 21 additions and 19 deletions

View File

@ -12,20 +12,25 @@ from helpers.functions import printfe, logo, _rainbow_color
def get_last_ssh_login():
"""Get information about the last SSH login"""
try:
# Using lastlog to get the last login information
# Using lastlog2 to get the last login information
result = subprocess.run(['lastlog2', '-u', os.environ.get("USER", "")],
capture_output=True, text=True)
if result.returncode == 0:
lines = result.stdout.strip().split('\n')
if len(lines) >= 2: # Header line + data line
# Parse the last login line for SSH connections
# Parse the last login line - example format:
# menno ssh 100.99.23.98 Mon Mar 10 19:09:43 +0100 2025
parts = lines[1].split()
if len(parts) >= 7 and 'ssh' in ' '.join(parts).lower():
time_str = ' '.join(parts[3:6])
ip = parts[-1]
if len(parts) >= 7 and 'ssh' in parts[1]: # Check if it's an SSH login
# Extract IP address from the third column
ip = parts[2]
# Time is the rest of the line starting from position 3
time_str = ' '.join(parts[3:])
return f"Last SSH login: {time_str} from {ip}"
return None
except Exception:
except Exception as e:
# For debugging, you might want to print the exception
# print(f"Error getting SSH login: {str(e)}")
return None
def check_dotfiles_status():
@ -133,16 +138,20 @@ def welcome():
hostname = os.uname().nodename
username = os.environ.get("USER", os.environ.get("USERNAME", "user"))
# Get SSH login info first
ssh_login = get_last_ssh_login()
print("\033[36mYou're logged in on [", end="")
print(_rainbow_color(hostname), end="")
print("\033[36m] as [", end="")
print(_rainbow_color(username), end="")
print("\033[36m]\033[0m")
print("\033[36m]", end="")
# Display last SSH login info if available
ssh_login = get_last_ssh_login()
# Display last SSH login info on the same line if available
if ssh_login:
print(f"\033[33m{ssh_login}\033[0m")
print(f" - \033[33m{ssh_login}\033[36m", end="")
print("\033[0m") # End the line after login info
# Display condensed status line
condensed_status = get_condensed_status()