PrettyPrompt/README.md

129 lines
4.7 KiB
Markdown
Raw Normal View History

2024-11-30 08:46:14 +00:00
# PrettyPrompt
2024-08-13 21:32:52 +00:00
2024-12-01 15:45:46 +00:00
A pretty shell prompt, written in rust.
2024-11-30 08:46:14 +00:00
## 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
2024-08-18 05:49:59 +00:00
## Screenshot
![screenshot](https://git.candifloss.cc/candifloss/PrettyPrompt/raw/branch/main/screenshot/BashPromptExampleScreenshoot.png "Screenshot")
2024-11-30 08:46:14 +00:00
## Planned Features
2024-12-01 13:01:07 +00:00
- **Right-hand side prompt**: Challenging to implement on non-zsh shells.
- **Configuration file**
2024-11-30 08:46:14 +00:00
- Choose only the components you need
- Change appearance
2024-12-01 13:01:07 +00:00
- Symbols and text
- Colors
- Order and position
- Custom components
- Static: Shell icon, Host name, etc.
2024-12-02 04:19:45 +00:00
- Dynamic: Time & date, system stats, or any custom commands
2024-11-30 08:46:14 +00:00
## Current Limitations
2024-12-01 13:01:07 +00:00
- **Hard-Coded Configuration**: User customization is not available yet.
- **Exit Code Requirement**: Must pass the last commands exit code as a command-line argument.
2024-11-30 08:46:14 +00:00
2024-11-30 11:17:36 +00:00
## Tested on
Ubuntu 24.04
- `bash` 5.2
- `zsh` 5.9
- `ion` 1.0.0-alpha
## Installation
2024-12-02 04:19:45 +00:00
**Step 1. Build binary from source**
This requires [rust](https://www.rust-lang.org/tools/install) installed on your system.
2024-11-30 11:17:36 +00:00
2024-12-01 13:01:07 +00:00
```bash
git clone https://git.candifloss.cc/candifloss/PrettyPrompt.git
cd PrettyPrompt/
cargo build --release
# Binary location: `target/release/prettyprompt`
2024-11-30 11:17:36 +00:00
```
2024-12-01 13:01:07 +00:00
**Step 2. Add to `$PATH`**
- Option 1. Move the binary to a directory in your `$PATH`. Eg:
```bash
2024-12-02 04:19:45 +00:00
sudo mv target/release/prettyprompt /usr/bin/
2024-11-30 11:17:36 +00:00
```
2024-12-01 13:01:07 +00:00
- 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/"
```
2024-11-30 11:17:36 +00:00
2024-11-30 08:46:14 +00:00
## Usage
2024-12-02 04:19:45 +00:00
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.
2024-11-30 08:46:14 +00:00
### `bash`
2024-11-30 11:17:36 +00:00
- The `PS1` variable sets a fixed prompt string.
2024-12-02 04:19:45 +00:00
- This `PROMPT_COMMAND` variable sets a dynamic prompt.
2024-11-30 11:17:36 +00:00
2024-12-01 13:01:07 +00:00
System-wide: `/etc/bash.bashrc`
User-specific: `~/.bashrc`:
2024-11-30 08:46:14 +00:00
```bash
2024-11-30 11:17:36 +00:00
PS1="" # Set it to an empty string
PROMPT_COMMAND='prettyprompt $?' # Single quotes, not double quotes
2024-11-30 08:46:14 +00:00
```
### `ion`
2024-12-01 13:01:07 +00:00
The `PROMPT` function is currently the only way to customize the prompt according to the `ion` shell docs.
User-specific config: `~/.config/ion/initrc`:
2024-11-30 08:46:14 +00:00
```ion
fn PROMPT
prettyprompt $?
end
```
2024-11-30 11:17:36 +00:00
### `zsh`
Export the `PS1` variable with the output of `prettyprompt $?` as its value.
2024-12-01 13:01:07 +00:00
User-specific: `~/.zshrc`
System-wide: `/etc/zsh/zshrc`
```sh
2024-12-02 04:19:45 +00:00
export PS1='$(prettyprompt $?)' # Notice the single quotes
2024-11-30 11:17:36 +00:00
```
2024-12-01 13:01:07 +00:00
### 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`.
2024-11-30 08:46:14 +00:00
## Changes since the last version
2024-12-02 04:19:45 +00:00
- **Updated Output String Type:** Ansi strings improved compatibility with other shells.
2024-11-30 08:46:14 +00:00
- **Revamped Indicator Symbols:** Enhanced the visual aspect of the prompt.
2024-12-01 13:01:07 +00:00
- **Removed Shell Icon:** Determining the shell is practically not possible.
2024-11-30 08:46:14 +00:00
- **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.
2024-11-30 11:17:36 +00:00
## Acknowledgement
2024-12-01 13:01:07 +00:00
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.
2024-12-01 15:45:46 +00:00
- **Portability**: Eliminates the need to write separate scripts in different shell languages for various shells.
2024-12-01 13:01:07 +00:00
- **Learning Rust**: Serves as a fun and practical project to learn and apply Rust programming skills.