feat: enhance SSH login display with color coding and refactor status output formatting
Some checks failed
Nix Format Check / check-format (push) Failing after 38s

This commit is contained in:
Menno van Leeuwen 2025-03-10 19:21:05 +01:00
parent 7afd1f0bca
commit e9bc1dcea3
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE

View File

@ -7,7 +7,7 @@ from datetime import datetime
# Import helper functions # Import helper functions
sys.path.append(os.path.join(os.path.expanduser("~/.dotfiles"), "bin")) sys.path.append(os.path.join(os.path.expanduser("~/.dotfiles"), "bin"))
from helpers.functions import printfe, logo, _rainbow_color from helpers.functions import printfe, logo, _rainbow_color, COLORS
def get_last_ssh_login(): def get_last_ssh_login():
"""Get information about the last SSH login""" """Get information about the last SSH login"""
@ -26,7 +26,7 @@ def get_last_ssh_login():
ip = parts[2] ip = parts[2]
# Time is the rest of the line starting from position 3 # Time is the rest of the line starting from position 3
time_str = ' '.join(parts[3:]) time_str = ' '.join(parts[3:])
return f"Last SSH login: {time_str} from {ip}" return f"{COLORS['cyan']}Last SSH login{COLORS['reset']}{COLORS['yellow']} {time_str}{COLORS['cyan']} from{COLORS['yellow']} {ip}"
return None return None
except Exception as e: except Exception as e:
# For debugging, you might want to print the exception # For debugging, you might want to print the exception
@ -91,13 +91,6 @@ def get_condensed_status():
"""Generate a condensed status line for trash and git status""" """Generate a condensed status line for trash and git status"""
status_parts = [] status_parts = []
# Define ANSI color codes
RED = "\033[31m"
YELLOW = "\033[33m"
GREEN = "\033[32m"
BLUE = "\033[34m"
RESET = "\033[0m"
# Check trash status # Check trash status
trash_path = os.path.expanduser("~/.local/share/Trash/files") trash_path = os.path.expanduser("~/.local/share/Trash/files")
try: try:
@ -113,13 +106,13 @@ def get_condensed_status():
dotfiles_status = check_dotfiles_status() dotfiles_status = check_dotfiles_status()
if dotfiles_status is not None: if dotfiles_status is not None:
if dotfiles_status['is_dirty']: if dotfiles_status['is_dirty']:
status_parts.append(f"{YELLOW}dotfiles is dirty{RESET}") status_parts.append(f"{COLORS['yellow']}dotfiles is dirty{COLORS['reset']}")
status_parts.append(f"{RED}[{dotfiles_status['untracked']}] untracked{RESET}") status_parts.append(f"{COLORS['red']}[{dotfiles_status['untracked']}] untracked{COLORS['reset']}")
status_parts.append(f"{YELLOW}[{dotfiles_status['modified']}] modified{RESET}") status_parts.append(f"{COLORS['yellow']}[{dotfiles_status['modified']}] modified{COLORS['reset']}")
status_parts.append(f"{GREEN}[{dotfiles_status['staged']}] staged{RESET}") status_parts.append(f"{COLORS['green']}[{dotfiles_status['staged']}] staged{COLORS['reset']}")
if dotfiles_status['commit_hash']: if dotfiles_status['commit_hash']:
status_parts.append(f"[{BLUE}{dotfiles_status['commit_hash']}{RESET}]") status_parts.append(f"[{COLORS['blue']}{dotfiles_status['commit_hash']}{COLORS['reset']}]")
if dotfiles_status['unpushed'] > 0: if dotfiles_status['unpushed'] > 0:
status_parts.append(f"[!] You have {dotfiles_status['unpushed']} commit(s) to push") status_parts.append(f"[!] You have {dotfiles_status['unpushed']} commit(s) to push")
@ -141,22 +134,20 @@ def welcome():
# Get SSH login info first # Get SSH login info first
ssh_login = get_last_ssh_login() ssh_login = get_last_ssh_login()
print("\033[36mYou're logged in on [", end="") print(f"{COLORS['cyan']}You're logged in on [", end="")
print(_rainbow_color(hostname), end="") print(_rainbow_color(hostname), end="")
print("\033[36m] as [", end="") print(f"{COLORS['cyan']}] as [", end="")
print(_rainbow_color(username), end="") print(_rainbow_color(username), end="")
print("\033[36m]", end="") print(f"{COLORS['cyan']}]{COLORS['reset']}")
# Display last SSH login info on the same line if available # Display last SSH login info if available
if ssh_login: if ssh_login:
print(f" - \033[33m{ssh_login}\033[36m", end="") print(f"{ssh_login}{COLORS['reset']}")
print("\033[0m") # End the line after login info
# Display condensed status line # Display condensed status line
condensed_status = get_condensed_status() condensed_status = get_condensed_status()
if condensed_status: if condensed_status:
print(f"\033[33m{condensed_status}\033[0m") print(f"{COLORS['yellow']}{condensed_status}{COLORS['reset']}")
def main(): def main():
logo(continue_after=True) logo(continue_after=True)