129 lines
4.7 KiB
Markdown
129 lines
4.7 KiB
Markdown
# PrettyPrompt
|
||
|
||
A pretty shell prompt, written in rust.
|
||
|
||
## Current Features
|
||
|
||
- **User indicator** - Symbol with different colors for root user and normal users
|
||
- **Error indicator** - Symbol with different colors to indicate if the last comment was successful
|
||
- **Git repo indicator**
|
||
- Indicates if the current directory is a repo or a regular directory
|
||
- Branches indicated by different colors
|
||
- **SSH indicator** - Symbol to indicate if the current shell is in an SSH session
|
||
- **Current directory**
|
||
- Abbreviated if the path is too long
|
||
- Replaces the user's home directory with a `~` symbol
|
||
- Show the repo's name if currently in a git repo
|
||
|
||
## Screenshot
|
||
|
||
![screenshot](https://git.candifloss.cc/candifloss/PrettyPrompt/raw/branch/main/screenshot/BashPromptExampleScreenshoot.png "Screenshot")
|
||
|
||
## Planned Features
|
||
|
||
- **Right-hand side prompt**: Challenging to implement on non-zsh shells.
|
||
- **Configuration file**
|
||
- Choose only the components you need
|
||
- Change appearance
|
||
- Symbols and text
|
||
- Colors
|
||
- Order and position
|
||
- Custom components
|
||
- Static: Shell icon, Host name, etc.
|
||
- Dynamic: Time & date, system stats, or any custom commands
|
||
|
||
## Current Limitations
|
||
|
||
- **Hard-Coded Configuration**: User customization is not available yet.
|
||
- **Exit Code Requirement**: Must pass the last command’s exit code as a command-line argument.
|
||
|
||
## Tested on
|
||
|
||
Ubuntu 24.04
|
||
- `bash` 5.2
|
||
- `zsh` 5.9
|
||
- `ion` 1.0.0-alpha
|
||
|
||
## Installation
|
||
|
||
**Step 1. Build binary from source**
|
||
This requires [rust](https://www.rust-lang.org/tools/install) installed on your system.
|
||
|
||
```bash
|
||
git clone https://git.candifloss.cc/candifloss/PrettyPrompt.git
|
||
cd PrettyPrompt/
|
||
cargo build --release
|
||
# Binary location: `target/release/prettyprompt`
|
||
```
|
||
|
||
**Step 2. Add to `$PATH`**
|
||
- Option 1. Move the binary to a directory in your `$PATH`. Eg:
|
||
```bash
|
||
sudo mv target/release/prettyprompt /usr/bin/
|
||
```
|
||
- Option 2. Add the directory containing the binary to `$PATH`
|
||
System-wide: `/etc/profile`
|
||
User-specific: `~/.profile`
|
||
Shell-specific: `bashrc`, `zshrc`, etc.
|
||
```bash
|
||
export PATH="$PATH:/path/where/the/binary/is/"
|
||
```
|
||
|
||
## Usage
|
||
|
||
Configuration varies by shell, and the file location varies by distro. Refer your shell's docs or community resources for details. Note that the exit code of the last command(usually `$?` variable) must be passed as a command-line argument.
|
||
|
||
### `bash`
|
||
|
||
- The `PS1` variable sets a fixed prompt string.
|
||
- This `PROMPT_COMMAND` variable sets a dynamic prompt.
|
||
|
||
System-wide: `/etc/bash.bashrc`
|
||
User-specific: `~/.bashrc`:
|
||
```bash
|
||
PS1="" # Set it to an empty string
|
||
PROMPT_COMMAND='prettyprompt $?' # Single quotes, not double quotes
|
||
```
|
||
|
||
### `ion`
|
||
|
||
The `PROMPT` function is currently the only way to customize the prompt according to the `ion` shell docs.
|
||
User-specific config: `~/.config/ion/initrc`:
|
||
```ion
|
||
fn PROMPT
|
||
prettyprompt $?
|
||
end
|
||
```
|
||
|
||
### `zsh`
|
||
Export the `PS1` 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
|
||
```
|
||
|
||
### Other shells
|
||
|
||
For other shells, refer their docs to set a dynamic prompt. Ensure the last command's exit code (`$?` or equivalent) is passed to `prettyprompt`.
|
||
|
||
## Changes since the last version
|
||
- **Updated Output String Type:** Ansi strings improved compatibility with other shells.
|
||
- **Revamped Indicator Symbols:** Enhanced the visual aspect of the prompt.
|
||
- **Removed Shell Icon:** Determining the shell is practically not possible.
|
||
- **Conditional Component Inclusion:** A first step towards user-configuration expected in future versions.
|
||
- **Code Improvements:** readability and performance
|
||
- **Refactoring:** Modular structure for better readability and maintenance.
|
||
- **Modularization:** Separate modules for cleaner organization.
|
||
- **Error Handling:** Improved logic to exclude error messages from the prompt.
|
||
- **Enhanced Documentation:** Comments for better comprehension.
|
||
|
||
## Acknowledgement
|
||
|
||
The current default (and only) theme draws inspiration from [s1ck94](https://github.com/zimfw/s1ck94) theme of [zimfw](https://zimfw.sh/).
|
||
|
||
## 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.
|
||
- **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. |