diff --git a/README.md b/README.md index 8f00cc8..8100371 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PrettyPrompt -A pretty shell prompt, written in rust +A pretty shell prompt, written in rust. ## Current Features @@ -126,5 +126,5 @@ The current default (and only) theme draws inspiration from [s1ck94](https://git ## Why this project? - **Efficiency**: Avoids repeated invocation of multiple binaries like `tr`, `grep`, `echo`, `git`, `sed`, etc., which would otherwise be used dozens of times in shell scripts just to generate a colored string. -- **Universality**: Eliminates the need to write separate scripts in different shell languages for various shells. +- **Portability**: Eliminates the need to write separate scripts in different shell languages for various shells. - **Learning Rust**: Serves as a fun and practical project to learn and apply Rust programming skills. \ No newline at end of file diff --git a/src/indicators/git.rs b/src/indicators/git.rs index bc5cf99..e459fe9 100644 --- a/src/indicators/git.rs +++ b/src/indicators/git.rs @@ -3,13 +3,13 @@ use ansi_term::Colour::RGB; use std::path::Path; use std::process::Command; -// SSH indicator symbol -pub const GIT_SYMBOL: &str = "\u{276F}"; // "❯" -pub const MAIN_COL: ansi_term::Colour = RGB(178, 98, 44); // -pub const DEV_COL: ansi_term::Colour = RGB(54, 159, 150); // -pub const OTHER_COL: ansi_term::Colour = RGB(82, 82, 82); // -pub const NORMIE_COL: ansi_term::Colour = RGB(255, 255, 255); // White +pub const GIT_SYMBOL: &str = "\u{276F}"; // Git indicator symbol: "❯" +pub const MAIN_COL: ansi_term::Colour = RGB(178, 98, 44); +pub const DEV_COL: ansi_term::Colour = RGB(54, 159, 150); +pub const DEFAULT_BRANCH_COL: ansi_term::Colour = RGB(255, 255, 255); +pub const NORMIE_COL: ansi_term::Colour = RGB(82, 82, 82); +/// Returns the repo's root and branch, if present pub fn info() -> Option<(String, String)> { let output = Command::new("git") // Program/Command to execute .args(["rev-parse", "--show-toplevel", "--abbrev-ref", "HEAD"]) // Arguments @@ -20,12 +20,13 @@ pub fn info() -> Option<(String, String)> { let output_str = String::from_utf8_lossy(&output.stdout).trim().to_string(); let parts: Vec<&str> = output_str.split('\n').collect(); if parts.len() == 2 { - return Some((parts[0].to_string(), parts[1].to_string())); + return Some((parts[0].to_string(), parts[1].to_string())); // If the `git`` command returns a repo and branch } } - None + None // If the current directory is not in a git repo } +/// The name of the repo pub fn repo_name(path: &str) -> String { Path::new(path) .file_name() // Extracts the last component of the path. @@ -34,13 +35,13 @@ pub fn repo_name(path: &str) -> String { .to_string() // Converts &str to String } -//Git branch indicator +/// Git branch indicator pub fn indicator(branch: Option) -> ANSIGenericString<'static, str> { match branch { Some(b) => match b.as_str() { "main" => MAIN_COL.paint(GIT_SYMBOL), "dev" => DEV_COL.paint(GIT_SYMBOL), - _ => OTHER_COL.paint(GIT_SYMBOL), + _ => DEFAULT_BRANCH_COL.paint(GIT_SYMBOL), }, None => NORMIE_COL.paint(GIT_SYMBOL), } diff --git a/src/indicators/ssh.rs b/src/indicators/ssh.rs index 0e9bc88..500b5eb 100644 --- a/src/indicators/ssh.rs +++ b/src/indicators/ssh.rs @@ -2,10 +2,9 @@ use ansi_term::ANSIGenericString; use ansi_term::Colour::RGB; use std::env::var; // For environment variables -/// Constants pub const SSH_SYMBOL: &str = "\u{276F}"; // SSH indicator symbol: "❯" pub const SSH_COL: ansi_term::Colour = RGB(255, 149, 0); // In SSH session -pub const NORMIE_COL: ansi_term::Colour = RGB(255, 255, 255); // Non-SSH session +pub const NORMIE_COL: ansi_term::Colour = RGB(82, 82, 82); // Non-SSH session const SSH_ENV_VARS: [&str; 2] = ["SSH_TTY", "SSH_CONNECTION"]; // Environment variables normally present in SSH sessions /// Checks if current session is an SSH session diff --git a/src/indicators/user.rs b/src/indicators/user.rs index 3521a58..451303f 100644 --- a/src/indicators/user.rs +++ b/src/indicators/user.rs @@ -7,11 +7,12 @@ pub const ROOT_COL: ansi_term::Colour = RGB(255, 53, 94); // If the user is root pub const NORMIE_COL: ansi_term::Colour = RGB(0, 255, 180); // Regular user const ROOT_USER: &str = "root"; // Root username constant -//Root user indicator +/// Username of current user pub fn username() -> String { var("USER").unwrap_or_else(|_| "UnknownUser".to_string()) } +/// Root user indicator pub fn indicator() -> ANSIGenericString<'static, str> { let user = username(); if user == ROOT_USER {