Core Modules

Base Module

Common base class for all classes in the sshmenuc project. Provides shared functionality and common patterns.

class sshmenuc.core.base.BaseSSHMenuC(config_file: str | None = None)[source]

Bases: ABC

Abstract base class with common functionality for all sshmenuc classes.

get_config() Dict[str, Any][source]

Return the current configuration.

Returns:

Configuration dictionary with ‘targets’ key

has_global_hosts() bool[source]

Check if there are any hosts in the configuration.

Returns:

True if at least one host entry exists, False otherwise

load_config()[source]

Load and normalize the configuration file.

When _encrypted_load is set (zero-plaintext mode), the config is read from the encrypted backend without touching any plaintext file. Otherwise, reads from the plaintext config_file (backward compat).

save_config()[source]

Save configuration.

When _encrypted_save is set (zero-plaintext mode), delegates to the encrypted backend without writing any plaintext file. Otherwise, writes to the plaintext config_file (backward compat).

set_config(config_data: Dict[str, Any])[source]

Set a new configuration.

Parameters:

config_data – New configuration dictionary to set

abstract validate_config() bool[source]

Abstract method to validate the configuration.

Must be implemented by subclasses to provide specific validation logic.

Returns:

True if configuration is valid, False otherwise

Config Module

SSH configuration management.

class sshmenuc.core.config.ConnectionManager(config_file: str | None = None)[source]

Bases: BaseSSHMenuC

Manages SSH connection configurations.

Provides CRUD operations for targets and connections within the configuration.

add_connection_at_path(path: List[int], connection: Dict[str, Any]) bool[source]

Append a connection dict to the list node at path.

add_subgroup_at_path(path: List[int], name: str) bool[source]

Append a subgroup {name: []} to the list node at path.

create_connection(target_name: str, friendly: str, host: str, connection_type: str = 'ssh', command: str = 'ssh', zone: str = '', project: str = '')[source]

Create a new connection within a target.

Parameters:
  • target_name – Name of the target to add connection to

  • friendly – Friendly name for the connection

  • host – Host address to connect to

  • connection_type – Type of connection (ssh, gssh, docker)

  • command – Command to execute for connection

  • zone – Cloud zone (for gssh connections)

  • project – Cloud project (for gssh connections)

create_target(target_name: str, connections: List[Dict[str, Any]])[source]

Create a new connection target.

Parameters:
  • target_name – Name of the target to create

  • connections – List of connection configuration dictionaries

delete_at_path(path: List[int], index: int) bool[source]

Remove item at index from the list node at path.

delete_connection(target_name: str, connection_index: int)[source]

Delete a connection.

Parameters:
  • target_name – Name of the target containing the connection

  • connection_index – Index of the connection to delete

delete_target(target_name: str)[source]

Delete a target.

Parameters:

target_name – Name of the target to delete

get_node_at_path(path: List[int]) Any[source]

Navigate config_data by index path and return the node.

Uses the same aggregated-dict traversal as ConnectionNavigator.get_node.

modify_connection(target_name: str, connection_index: int, **kwargs)[source]

Modify an existing connection.

Parameters:
  • target_name – Name of the target containing the connection

  • connection_index – Index of the connection to modify

  • **kwargs – Connection fields to update (host, user, certkey, etc.)

modify_target(target_name: str, new_target_name: str = None, connections: List[Dict[str, Any]] = None)[source]

Modify an existing target.

Parameters:
  • target_name – Current name of the target

  • new_target_name – New name for the target (optional, if renaming)

  • connections – New connection list (optional, if updating connections)

rename_subgroup_at_path(path: List[int], index: int, new_name: str) bool[source]

Rename the key of a subgroup dict at index in the list node at path.

search_hosts(query: str) List[Tuple[str, Dict[str, Any]]][source]

Search all host entries matching query against friendly name, host, and tags.

Parameters:

query – Case-insensitive substring to search for.

Returns:

List of (breadcrumb, host_entry) tuples for matching hosts.

validate_config() bool[source]

Validate the configuration structure.

Returns:

True if config has valid structure with ‘targets’ key, False otherwise

Config Editor Module

Interactive configuration editor for managing targets and connections.

class sshmenuc.core.config_editor.ConfigEditor(config_manager: ConnectionManager)[source]

Bases: object

Interactive editor for SSH configuration.

Provides forms and dialogs for creating, editing, and deleting targets and connections within the configuration.

__init__(config_manager: ConnectionManager)[source]

Initialize the config editor.

Parameters:

config_manager – ConnectionManager instance to modify

add_connection(target_name: str) bool[source]

Interactive form to add a connection to a target.

Parameters:

target_name – Target to add connection to

Returns:

True if connection added, False if cancelled

add_connection_to_path(path: List[int]) bool[source]

Interactive form to add a connection to the list node at path.

Parameters:

path – Navigation path to the target list node.

Returns:

True if connection added, False if cancelled.

add_subgroup(path: List[int]) bool[source]

Interactive form to create a subgroup at path.

Parameters:

path – Navigation path to the parent list node.

Returns:

True if subgroup created, False if cancelled.

add_target() bool[source]

Interactive form to add a new target.

Returns:

True if target was added, False if cancelled

confirm(message: str) bool[source]

Ask user for confirmation.

Parameters:

message – Confirmation message

Returns:

True if user confirms, False otherwise

delete_connection(target_name: str, connection_index: int, connection: Dict[str, Any]) bool[source]

Delete a connection with confirmation.

Parameters:
  • target_name – Target containing the connection

  • connection_index – Index of connection to delete

  • connection – Connection data (for display)

Returns:

True if deleted, False if cancelled

delete_connection_at_path(path: List[int], index: int, connection: Dict[str, Any]) bool[source]

Confirm and delete a host connection at path[index].

Parameters:
  • path – Navigation path to the parent list node.

  • index – Index of the connection within that list.

  • connection – Connection data (for display).

Returns:

True if deleted, False if cancelled.

delete_subgroup(path: List[int], index: int, name: str) bool[source]

Confirm and delete a subgroup at path[index].

Parameters:
  • path – Navigation path to the parent list node.

  • index – Index of the subgroup within that list.

  • name – Display name of the subgroup.

Returns:

True if deleted, False if cancelled.

delete_target(target_name: str) bool[source]

Delete a target with confirmation.

Parameters:

target_name – Name of target to delete

Returns:

True if deleted, False if cancelled

edit_connection(target_name: str, connection_index: int, connection: Dict[str, Any]) bool[source]

Interactive form to edit a connection.

Parameters:
  • target_name – Target containing the connection

  • connection_index – Index of connection to edit

  • connection – Current connection data

Returns:

True if edited, False if cancelled

edit_connection_at_path(path: List[int], index: int, connection: Dict[str, Any]) bool[source]

Interactive form to edit an existing connection at path[index].

Parameters:
  • path – Navigation path to the parent list node.

  • index – Index of the connection within that list.

  • connection – Current connection data.

Returns:

True if edited, False if cancelled.

prompt_input(prompt: str, default: str = '') str[source]

Prompt user for input with optional default value.

Parameters:
  • prompt – Prompt message to display

  • default – Default value if user presses enter

Returns:

User input string

rename_subgroup(path: List[int], index: int, current_name: str) bool[source]

Interactive form to rename a subgroup at path[index].

Parameters:
  • path – Navigation path to the parent list node.

  • index – Index of the subgroup within that list.

  • current_name – Current key name of the subgroup.

Returns:

True if renamed, False if cancelled.

rename_target(target_name: str) bool[source]

Rename a target.

Parameters:

target_name – Current name of target

Returns:

True if renamed, False if cancelled

Navigation Module

Menu navigation management.

class sshmenuc.core.navigation.ConnectionNavigator(config_file: str, sync_cfg_override: dict | None = None, context_manager=None, active_context: str | None = None)[source]

Bases: BaseSSHMenuC

Manages navigation through the connection menu.

Provides interactive keyboard navigation with support for multiple selection and tmux integration for group connections.

count_elements(current_path: List[Any]) int[source]

Count elements in the current node.

Parameters:

current_path – Current navigation path

Returns:

Number of items in the current node

get_node(path: List[Any])[source]

Return the current node at the given path.

Parameters:

path – Navigation path as list of indices

Returns:

The node at the specified path (dict, list, or host entry)

get_previous_node(path: List[Any])[source]

Return the previous node in the path.

Parameters:

path – Navigation path as list of indices

Returns:

-1]

Return type:

The node at path[

Raises:
  • KeyError – If a key in the path is not found

  • TypeError – If node type is not dict or list

move_left(current_path: List[Any])[source]

Handle left navigation (go back).

Parameters:

current_path – Current navigation path (modified in place)

navigate()[source]

Main navigation loop.

Handles keyboard input for menu navigation: - Arrow keys: Move selection up/down/left/right - Space: Toggle selection for multi-host connection - Enter: Navigate into sub-menu or launch connection(s) - q: Quit application (requires y/Y confirmation)

print_menu(selected_target: int, current_path: List[Any])[source]

Print the current menu.

Parameters:
  • selected_target – Index of the currently selected item

  • current_path – Current navigation path

validate_config() bool[source]

Validate the configuration for navigation.

Returns:

True if config is valid dict with ‘targets’ key, False otherwise

Launcher Module

SSH connection launching management.

class sshmenuc.core.launcher.SSHLauncher(host: str, username: str, port: int = 22, identity_file: str | None = None, extra_args: str | None = None)[source]

Bases: object

Manages SSH connection launching with tmux integration.

Supports both single and group connections with automatic tmux session management.

launch()[source]

Launch SSH connection with tmux if available.

If tmux is available, creates/attaches to a tmux session. Otherwise falls back to direct SSH connection.

static launch_group(host_entries: List[Dict[str, Any]])[source]

Launch multiple connections in a tmux session with split panes.

Parameters:

host_entries – List of host entry dictionaries with connection details