Skip to main content

Crate onpath

Crate onpath 

Source
Expand description

Safe, idempotent PATH management across shells and operating systems.

onpath lets any Rust CLI tool or installer add directories to the user’s PATH persistently — across Bash, Zsh, Fish, Nushell, PowerShell, Tcsh, Xonsh, and Windows (via the registry).

§Quick Start

// Add ~/.myapp/bin to PATH for all detected shells
let report = onpath::add("/home/user/.myapp/bin", "myapp")?;
println!("{report}");

§How It Works

On Unix, onpath uses a two-layer approach (pioneered by rustup):

  1. Env scripts — Self-guarding shell scripts that check if the directory is already in PATH before adding it (e.g., ~/.myapp/env, ~/.myapp/env.fish).

  2. Source lines — A single source line added to each shell’s RC file, bracketed with identifiable markers for clean removal.

On Windows, it modifies HKCU\Environment\PATH in the registry and broadcasts WM_SETTINGCHANGE to notify running applications.

Re-exports§

pub use config::Position;
pub use error::Error;
pub use manager::PathManager;
pub use report::Action;
pub use report::ActionKind;
pub use report::Report;
pub use shell_kind::ShellKind;

Modules§

config
PATH position configuration.
error
Error types for PATH management operations.
manager
The PathManager builder for configuring PATH operations.
report
Report types describing actions taken during PATH operations.
shell_kind
Shell type identifiers shared across all platforms.

Structs§

SystemContext
System context providing home directory and environment variables.

Functions§

add
Convenience function: add a directory to PATH for all detected shells.
remove
Convenience function: remove a directory from PATH for all detected shells.