Compare commits

..

3 Commits
main ... dev

Author SHA1 Message Date
b078a62152 Typo 2024-12-02 13:06:27 +05:30
1452b6db45 Fixed zsh instruction in README 2024-12-02 11:15:24 +05:30
0520af5673 Fixed README zsh section 2024-12-02 10:27:43 +05:30
6 changed files with 28 additions and 46 deletions

2
Cargo.lock generated
View File

@ -13,7 +13,7 @@ dependencies = [
[[package]]
name = "prettyprompt"
version = "0.3.0"
version = "0.2.0"
dependencies = [
"ansi_term",
]

View File

@ -1,15 +1,7 @@
[package]
name = "prettyprompt"
version = "0.3.0"
version = "0.2.0"
edition = "2021"
[dependencies]
ansi_term = "0.12"
[[bin]]
name = "prettyprompt"
path = "src/prettyprompt.rs"
[[bin]]
name = "prettyprompt-pwd"
path = "src/prettyprompt_pwd.rs"

View File

@ -35,7 +35,7 @@ A pretty shell prompt, written in rust.
## Current Limitations
- **Hard-Coded Configuration**: User customization is not available yet.
- **Exit Code Requirement**: Must pass the last commands exit code as a command-line argument.
- **Exit Code Requirement**: Must pass the last command's exit code as a command-line argument.
## Tested on
@ -59,7 +59,7 @@ cargo build --release
**Step 2. Add to `$PATH`**
- Option 1. Move the binary to a directory in your `$PATH`. Eg:
```bash
sudo mv target/release/prettyprompt target/release/prettyprompt-pwd /usr/bin/
sudo mv target/release/prettyprompt /usr/bin/
```
- Option 2. Add the directory containing the binary to `$PATH`
System-wide: `/etc/profile`
@ -96,11 +96,13 @@ end
```
### `zsh`
Export the `PS1` variable with the output of `prettyprompt $?` as its value.
Use the precmd function to set the `PROMPT` variable with the output of `prettyprompt $?` as its value.
User-specific: `~/.zshrc`
System-wide: `/etc/zsh/zshrc`
```sh
export PS1='$(prettyprompt $?)' # Notice the single quotes
```zsh
precmd() {
PROMPT="$(prettyprompt $?)" # Notice the double quotes
}
```
### Other shells

View File

@ -1,11 +1,12 @@
mod indicators {
pub mod error;
pub mod git;
pub mod pwd;
pub mod ssh;
pub mod user;
}
use crate::indicators::{error, git, ssh, user};
use crate::indicators::{error, git, pwd, ssh, user};
use ansi_term::{ANSIGenericString, ANSIGenericStrings};
// Add a component to the prompt if the condition is true.
@ -30,9 +31,13 @@ fn main() {
let indicate_ssh: bool = true;
let indicate_err: bool = true;
let indicate_git_branch: bool = true;
let show_pwd: bool = true;
let abbrev_home: bool = true;
let shorten_path: bool = true;
let replace_repo: bool = true;
// Conditionally fetch Git-related info if required, or set to None
let git_info: Option<(String, String)> = if indicate_git_branch {
let git_info: Option<(String, String)> = if indicate_git_branch || replace_repo {
git::info()
} else {
None
@ -48,6 +53,15 @@ fn main() {
error::indicator(&cmd_args)
});
// Insert `pwd` at the beginning of the prompt
if show_pwd {
let repo_path = git_info.map(|info| info.0);
components.insert(
0,
pwd::pwd(abbrev_home, shorten_path, replace_repo, repo_path),
);
}
// Finally, combine the parts into a single prompts string
let prompt: ANSIGenericStrings<'_, str> = ANSIGenericStrings(&components[..]);
// `print!()` prevents an extra newline, unlike `println!()`

View File

@ -1,26 +0,0 @@
mod indicators {
pub mod git;
pub mod pwd;
}
use crate::indicators::{git, pwd};
fn main() {
// Hard-coded configuration. This will be replaced by a configuration file in a future version
let indicate_git_branch: bool = true;
let abbrev_home: bool = true;
let shorten_path: bool = true;
let replace_repo: bool = true;
// Conditionally fetch Git-related info if required, or set to None
let git_info: Option<(String, String)> = if indicate_git_branch || replace_repo {
git::info()
} else {
None
};
let repo_path = git_info.map(|info| info.0);
let promt_pwd = pwd::pwd(abbrev_home, shorten_path, replace_repo, repo_path);
print!("{promt_pwd}"); // A trailing space for aesthetic formatting.
}