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
Some checks failed
Nix Format Check / check-format (push) Failing after 37s
This commit is contained in:
parent
3e9e83e25d
commit
7afd1f0bca
@ -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()
|
||||
|
@ -56,12 +56,7 @@ def logo(continue_after=False):
|
||||
"""Display the dotfiles logo"""
|
||||
try:
|
||||
# Try to read logo file first for backward compatibility
|
||||
logo_path = f"{os.environ.get('DOTFILES_PATH', os.path.expanduser('~/.dotfiles'))}/bin/resources/logo.txt"
|
||||
if os.path.exists(logo_path):
|
||||
with open(logo_path, "r") as f:
|
||||
logo_text = f.read()
|
||||
print(logo_text)
|
||||
elif pyfiglet:
|
||||
if pyfiglet:
|
||||
# Generate ASCII art with pyfiglet and rainbow colors
|
||||
ascii_art = pyfiglet.figlet_format("Menno's Dotfiles", font='slant')
|
||||
print("\n") # Add some space before the logo
|
||||
@ -74,11 +69,9 @@ def logo(continue_after=False):
|
||||
# Add a little variation to each line
|
||||
print(_rainbow_color(line, offset=random_offset + line_offset))
|
||||
line_offset += 0.1
|
||||
|
||||
print("\n") # Add some space after the logo
|
||||
else:
|
||||
# Fallback if pyfiglet is not available
|
||||
printfe("yellow", "\n\n *** Menno's Dotfiles ***\n\n")
|
||||
printfe("yellow", "\n *** Menno's Dotfiles ***\n")
|
||||
printfe("cyan", " Note: Install pyfiglet for better logo display")
|
||||
printfe("cyan", " (pip install pyfiglet)\n")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user