Skip to main content

SshConfigFile

Struct SshConfigFile 

Source
pub struct SshConfigFile {
    pub elements: Vec<ConfigElement>,
    pub path: PathBuf,
    pub crlf: bool,
    pub bom: bool,
}
Expand description

Represents the entire SSH config file as a sequence of elements. Preserves the original structure for round-trip fidelity.

Fields§

§elements: Vec<ConfigElement>§path: PathBuf§crlf: bool

Whether the original file used CRLF line endings.

§bom: bool

Whether the original file started with a UTF-8 BOM.

Implementations§

Source§

impl SshConfigFile

Source

pub fn host_entries(&self) -> Vec<HostEntry>

Get all host entries as convenience views (including from Include files).

Source

pub fn include_paths(&self) -> Vec<PathBuf>

Collect all resolved Include file paths (recursively).

Source

pub fn include_glob_dirs(&self) -> Vec<PathBuf>

Collect parent directories of Include glob patterns. When a file is added/removed under a glob dir, the directory’s mtime changes.

Source

pub fn remove_all_orphaned_group_headers(&mut self) -> usize

Remove # purple:group <Name> headers that have no corresponding provider hosts. Returns the number of headers removed.

Source

pub fn repair_absorbed_group_comments(&mut self) -> usize

Repair configs where # purple:group comments were absorbed into the preceding host block’s directives instead of being stored as GlobalLines. Returns the number of blocks that were repaired.

Source

pub fn has_host(&self, alias: &str) -> bool

Check if a host alias already exists (including in Include files). Walks the element tree directly without building HostEntry structs.

Source

pub fn is_included_host(&self, alias: &str) -> bool

Check if a host alias is from an included file (read-only). Handles multi-pattern Host lines by splitting on whitespace.

Source

pub fn add_host(&mut self, entry: &HostEntry)

Add a new host entry to the config. Inserts before any trailing wildcard/pattern Host blocks (e.g. Host *) so that SSH “first match wins” semantics are preserved. If wildcards are only at the top of the file (acting as global defaults), appends at end.

Source

pub fn last_element_has_trailing_blank(&self) -> bool

Check if the last element already ends with a blank line.

Source

pub fn update_host(&mut self, old_alias: &str, entry: &HostEntry)

Update an existing host entry by alias. Merges changes into the existing block, preserving unknown directives.

Source

pub fn set_host_provider( &mut self, alias: &str, provider_name: &str, server_id: &str, )

Set provider on a host block by alias.

Source

pub fn find_hosts_by_provider( &self, provider_name: &str, ) -> Vec<(String, String)>

Find all hosts with a specific provider, returning (alias, server_id) pairs. Searches both top-level elements and Include files so that provider hosts in included configs are recognized during sync (prevents duplicate additions).

Source

pub fn add_forward(&mut self, alias: &str, directive_key: &str, value: &str)

Add a forwarding directive to a host block. Inserts at content_end() (before trailing blanks), using detected indentation. Uses split_whitespace matching for multi-pattern Host lines.

Source

pub fn remove_forward( &mut self, alias: &str, directive_key: &str, value: &str, ) -> bool

Remove a specific forwarding directive from a host block. Matches key (case-insensitive) and value (whitespace-normalized). Uses split_whitespace matching for multi-pattern Host lines. Returns true if a directive was actually removed.

Source

pub fn has_forward(&self, alias: &str, directive_key: &str, value: &str) -> bool

Check if a host block has a specific forwarding directive. Uses whitespace-normalized value comparison and split_whitespace host matching.

Source

pub fn find_tunnel_directives(&self, alias: &str) -> Vec<TunnelRule>

Find tunnel directives for a host alias, searching all elements including Include files. Uses split_whitespace matching like has_host() for multi-pattern Host lines.

Source

pub fn deduplicate_alias(&self, base: &str) -> String

Generate a unique alias by appending -2, -3, etc. if the base alias is taken.

Source

pub fn deduplicate_alias_excluding( &self, base: &str, exclude: Option<&str>, ) -> String

Generate a unique alias, optionally excluding one alias from collision detection. Used during rename so the host being renamed doesn’t collide with itself.

Source

pub fn set_host_tags(&mut self, alias: &str, tags: &[String])

Set tags on a host block by alias.

Source

pub fn set_host_askpass(&mut self, alias: &str, source: &str)

Set askpass source on a host block by alias.

Source

pub fn set_host_meta(&mut self, alias: &str, meta: &[(String, String)])

Set provider metadata on a host block by alias.

Source

pub fn delete_host(&mut self, alias: &str)

Delete a host entry by alias.

Source

pub fn delete_host_undoable( &mut self, alias: &str, ) -> Option<(ConfigElement, usize)>

Delete a host and return the removed element and its position for undo. Does NOT collapse blank lines or remove group headers so the position stays valid for re-insertion via insert_host_at(). Orphaned group headers (if any) are cleaned up at next startup.

Source

pub fn insert_host_at(&mut self, element: ConfigElement, position: usize)

Insert a host block at a specific position (for undo).

Source

pub fn find_provider_insert_position( &self, provider_name: &str, ) -> Option<usize>

Find the position after the last HostBlock that belongs to a provider. Returns None if no hosts for this provider exist in the config. Used by the sync engine to insert new hosts adjacent to existing provider hosts.

Source

pub fn swap_hosts(&mut self, alias_a: &str, alias_b: &str) -> bool

Swap two host blocks in the config by alias. Returns true if swap was performed.

Source§

impl SshConfigFile

Source

pub fn parse(path: &Path) -> Result<Self>

Parse an SSH config file from the given path. Preserves all formatting, comments, and unknown directives for round-trip fidelity.

Source

pub fn parse_content(content: &str) -> Vec<ConfigElement>

Parse SSH config content from a string (without Include resolution). Used by tests to create SshConfigFile from inline strings.

Source§

impl SshConfigFile

Source

pub fn write(&self) -> Result<()>

Write the config back to disk. Creates a backup before writing and uses atomic write (temp file + rename). Resolves symlinks so the rename targets the real file, not the link. Acquires an advisory lock to prevent concurrent writes from multiple purple processes or background sync threads.

Source

pub fn serialize(&self) -> String

Serialize the config to a string. Collapses consecutive blank lines to prevent accumulation after deletions.

Trait Implementations§

Source§

impl Clone for SshConfigFile

Source§

fn clone(&self) -> SshConfigFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SshConfigFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V