prmt 0.2.0

Ultra-fast, customizable shell prompt generator with zero-copy parsing
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# prmt ๐Ÿš€

> Ultra-fast, customizable shell prompt that won't slow you down

[![Crates.io](https://img.shields.io/crates/v/prmt.svg)](https://crates.io/crates/prmt)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Rust](https://img.shields.io/badge/rust-2024-orange.svg)](https://www.rust-lang.org)

![Terminal](./terminal.png)

> Rendered with `"{path:#89dceb}{rust:#f38ba8:f: ๐Ÿฆ€}{git:#f9e2af:f: }\n{ok:#a6e3a1}{fail:#f38ba8} "`

## Features

- **โšก Blazing Fast**: Sub-millisecond rendering for typical prompts (~2ms end-to-end)
- **๐ŸŽจ Highly Customizable**: Full control over colors, formats, and what information to show
- **๐Ÿš€ Context Aware**: Automatically detects git repos, project files, shows only what's relevant
- **๐Ÿ“ฆ Zero Dependencies**: Single binary, no runtime dependencies required
- **๐Ÿฆ€ Memory Efficient**: Zero-copy parsing with SIMD optimizations
- **โœจ Smart Rendering**: Only shows information when relevant to your current directory

## Why prmt?

**Faster than alternatives** โ€“ Typical prompts render in ~2ms. Starship averages 10-50ms, oh-my-posh 20-100ms.

**Zero configuration needed** โ€“ Works out of the box with sensible defaults. Customize only what you want.

**Predictable performance** โ€“ No async operations, no network calls, no surprises. Your prompt is always instant.

**Single binary** โ€“ Just install and go. No configuration files required unless you want them.

**Context-aware** โ€“ Automatically detects git repositories, Rust/Node/Python projects, and shows only relevant info.

## Quick Start

**1. Install**
```bash
cargo install prmt
```

**2. Add to your shell** (pick one)

**Bash** โ€“ Add to `~/.bashrc`:
```bash
# Simple with named colors
PS1='$(prmt --code $? "{path:cyan} {git:purple} {ok:green}{fail:red} ")'

# Explicit shell wrapping (recommended for prompt usage)
PS1='$(prmt --shell bash --code $? "{path:cyan} {git:purple} {ok:green}{fail:red} ")'

# Or with hex colors for precise theming
PS1='$(prmt --code $? "{path:#89dceb} {git:#f9e2af} {ok:#a6e3a1}{fail:#f38ba8} ")'
```

**Zsh** โ€“ Add to `~/.zshrc` (auto-detected by default; `--shell zsh` forces wrapping):
```bash
setopt PROMPT_SUBST

# Simple with named colors
PROMPT='$(prmt --shell zsh --code $? "{path:cyan} {git:purple} {ok:green}{fail:red} ")'

# Or with hex colors for precise theming
PROMPT='$(prmt --shell zsh --code $? "{path:#89dceb} {git:#f9e2af} {ok:#a6e3a1}{fail:#f38ba8} ")'
```

**Fish** โ€“ Add to `~/.config/fish/config.fish`:
```fish
function fish_prompt
    prmt --code $status '{path:cyan} {git:purple} {ok:green}{fail:red} '
end
```

**3. Reload your shell**
```bash
exec $SHELL  # or open a new terminal
```

Done! ๐ŸŽ‰

<details>
<summary>Advanced setup (PROMPT_COMMAND, precmd, environment variables)</summary>

### Bash with PROMPT_COMMAND
```bash
function _prmt_prompt() {
    local last=$?
    PS1="$(prmt --code $last '{path:cyan} {git:purple} {ok:green}{fail:red}')"
}
PROMPT_COMMAND=_prmt_prompt
```

*If you already use `PROMPT_COMMAND`, append `_prmt_prompt` instead of overwriting it.*

### Zsh with precmd
```zsh
function _prmt_precmd() {
    local code=$?
    PROMPT="$(prmt --code $code '{path:cyan} {git:purple} {ok:green}{fail:red}')"
}
typeset -ga precmd_functions
precmd_functions+=(_prmt_precmd)
```

### PowerShell
```powershell
# Add to $PROFILE
function prompt {
    prmt --code $LASTEXITCODE '{path:cyan:s} {git:purple:s:on :} {ok:green}{fail:red} '
}
```

### Environment Variable
All shells support using `PRMT_FORMAT` environment variable:

```bash
# Bash/Zsh
export PRMT_FORMAT="{path:cyan:r} {rust:red:m:v ๐Ÿฆ€} {git:purple}"
PS1='$(prmt --code $?)\$ '

# Fish
set -x PRMT_FORMAT "{path:cyan:r} {python:yellow:m: ๐Ÿ} {git:purple}"

# PowerShell
$env:PRMT_FORMAT = "{path:cyan:r} {git:purple}"
```

</details>

## Popular Prompts

**Minimal**
```bash
prmt '{path:cyan:s} {ok:green}{fail:red} '
# Output: projects โฏ
```

**Developer**
```bash
prmt '{path:cyan} {git:purple} {rust:red:s: ๐Ÿฆ€} {node:green:s: โฌข} {ok:green}{fail:red} '
# Output: ~/projects/prmt on main ๐Ÿฆ€1.90 โฌข20.5 โฏ
```

**Identity (via env module)**
```bash
prmt '{env::USER}@{env::HOSTNAME} {path:cyan:s} {git:purple} {ok:green}{fail:red} '
# Output: zenpie@workbox projects on main โฏ
```

**Compact with time**
```bash
prmt '{time:dim:12h} {path:cyan:s} {git:purple:s} {ok:green}{fail:red} '
# Output: 02:30PM projects main โฏ
```

**Full featured with newline**
```bash
prmt '{path:cyan} {git:purple} {python:yellow:m: ๐Ÿ} {time:dim}\n{ok:green}{fail:red} '
# Output: ~/ml-project on develop ๐Ÿ3.11 14:30
#         โฏ
```

**Status-focused**
```bash
prmt '{path:cyan:s} {git:purple:s:on :} {ok:green:โœ“}{fail:red:โœ—} '
# Output (success): projects on main โœ“
# Output (failure): projects on main โœ—
```

**With exit codes**
```bash
prmt '{path:cyan} {git:purple} {ok:green:โฏ}{fail:red::code} '
# Output (success): ~/projects main โฏ
# Output (failure): ~/projects main 127
```

## Installation

```bash
# Install from crates.io
cargo install prmt

# Build from source (Rust 2024 edition required)
cargo build --release
cp target/release/prmt ~/.local/bin/

# Or install directly from source
cargo install --path .

# Verify installation
prmt --version
```

## Usage Examples

```bash
# Simple format with defaults
prmt '{path} {rust} {git}'
# Output: ~/projects 1.89.0 master

# Format with types and styles
prmt '{path::a}'                  # /home/user/projects (absolute path)
prmt '{path::r}'                  # ~/projects (relative with ~)
prmt '{path::s}'                  # projects (short - last dir only)
prmt '{rust:red:s}'               # 1.89 in red (short version)
prmt '{rust:red:m:v:}'            # v1 in red (major version with prefix)
prmt '{path:cyan:s:[:]}'          # [projects] in cyan
prmt '{git:purple::on :}'         # on master in purple

# Simplified formats with omitted parts
prmt '{rust::::!}'                # 1.89.0! (default style/type, suffix only)
prmt '{rust:::v:}'                # v1.89.0 (default style/type, prefix only)
prmt '{path::::]}'                # ~/projects] (suffix only)
prmt '{git:::on :}'               # on master (prefix only)

# Add your own icons with prefix
prmt '{rust::: ๐Ÿฆ€}'               # ๐Ÿฆ€1.89.0 (default color)
prmt '{node:green:: โฌข}'           # โฌข20.5.0 in green
prmt '{python:yellow:: ๐Ÿ}'       # ๐Ÿ3.11.0 in yellow

# Or add spacing with suffix for better readability
prmt '{rust::: ๐Ÿฆ€ }'              # ๐Ÿฆ€ 1.89.0 (space after icon)
prmt '{node:green:: โฌข }'          # โฌข 20.5.0 (space after icon)

# Using short format aliases
prmt '{path:cyan:s} {rust:red:m:v:}' # projects v1 (both in color)
prmt '{git::s:on :}'              # on master (short format with prefix)

# No style with type
prmt '{path::s}'                  # projects (no color, short)
prmt '{path::a}'                  # /home/user/projects (no color, absolute)
prmt '{rust::m:v}'                # v1 (no color, major with prefix)

# With exit code indicators (requires --code flag)
prmt --code $? '{path:cyan} {ok:green}{fail:red}'
# Output (success): ~/projects โฏ (green)
# Output (failure): ~/projects โฏ (red)

# Fast mode (no version detection)
prmt --no-version '{path:cyan} {rust:red} {node:green}'
# Output: ~/projects (only shows active modules, no versions)

# Custom symbols for ok/fail using type as symbol
prmt --code $? '{path} {ok::โœ“} {fail::โœ—}'
# Output (success): ~/projects โœ“
# Output (failure): ~/projects โœ—

# Show exit code on failure
prmt --code $? '{path} {ok::โฏ} {fail::code}'
# Output (success): ~/projects โฏ
# Output (failure with code 127): ~/projects 127

# Time formats
prmt '{time}'                     # 14:30 (default 24h)
prmt '{time::24hs}'               # 14:30:45
prmt '{time::12h}'                # 02:30PM
prmt '{time::12hs}'               # 02:30:45PM
prmt '{path:cyan} {time:dim:12h}' # ~/projects 02:30PM (with styling)
```

## Format Specification

### Format Syntax
```
{module}                      - Default everything
{module:style}                - Custom style
{module:style:type}           - Custom style and type
{module:style:type:prefix}    - Add prefix to value
{module:style:type:prefix:postfix} - Add prefix and postfix

# Omitting parts (empty means default)
{module::::suffix}            - Default style/type, suffix only
{module:::prefix:}            - Default style/type, prefix only
{module:::prefix:suffix}      - Default style/type, both prefix/suffix
{module::type}                - No style, specific type
{module::type::suffix}        - No style, specific type, suffix only
```

### Available Modules

| Module | Detection | Description |
|--------|-----------|-------------|
| `path` | Always active | Current directory with ~ for home |
| `ok` | Exit code = 0 | Shows when last command succeeded (default: โฏ) |
| `fail` | Exit code โ‰  0 | Shows when last command failed (default: โฏ) |
| `git` | `.git` directory | Branch name with status indicators |
| `node` | `package.json` | Node.js version |
| `python` | `requirements.txt`, `pyproject.toml`, etc | Python version |
| `rust` | `Cargo.toml` | Rust version |
| `deno` | `deno.json`, `deno.jsonc` | Deno version |
| `bun` | `bun.lockb` | Bun version |
| `go` | `go.mod` | Go version |
| `env` | Requested variable is set/non-empty | Value of a specific environment variable (format = name) |
| `time` | Always active | Current time in various formats |

### Type Values

**Version modules** (rust, node, python, etc.):
- `full` or `f` - Full version (1.89.0)
- `short` or `s` - Major.minor (1.89)
- `major` or `m` - Major only (1)

**Path module**:
- `relative` or `r` - Path with ~ for home directory (default)
- `absolute`, `a`, or `f` - Full absolute path without ~ substitution
- `short` or `s` - Last directory only

**Git module**:
- `full` or `f` - Branch with status (default)
- `short` or `s` - Branch name only
- Add `+owned` (or `+o`) to show only repos owned by the current user (e.g., `{git::full+owned}`)

**Ok/Fail modules**:
- `full` - Default symbol (โฏ)
- `code` - Shows the actual exit code number
- *Any other string* - Uses that string as the symbol (e.g., `{ok::โœ“}` shows โœ“)

**Time module**:
- `24h` - 24-hour format HH:MM (default)
- `24hs` or `24HS` - 24-hour format with seconds HH:MM:SS
- `12h` or `12H` - 12-hour format hh:MMAM/PM
- `12hs` or `12HS` - 12-hour format with seconds hh:MM:SSAM/PM

**Env module**:
- The `type` field is required and must be the environment variable name (e.g., `{env::USER}` or `{env:blue:PATH}`).
- The module emits the variable value only when it exists and is non-empty; otherwise it returns nothing so the placeholder is effectively inactive.
- Example for identity: `{env::USER}@{env::HOSTNAME}`

### Type Validation

The format parser validates types at parse time to catch errors early:

```bash
# Valid types for each module
prmt '{path::short}'     # โœ“ Valid
prmt '{rust::major}'     # โœ“ Valid
prmt '{ok::โœ“}'          # โœ“ Valid (custom symbol)
prmt '{fail::code}'     # โœ“ Valid (shows exit code)

# Invalid types produce clear errors
prmt '{path::major}'
# Error: Invalid type 'major' for module 'path'. Valid types: relative, r, absolute, a, short, s

prmt '{git::major}'
# Error: Invalid type 'major' for module 'git'. Valid types: full, short
```

### Default Module Styles

| Module | Default Color | Can Override |
|--------|--------------|--------------|
| `path` | cyan | Yes |
| `ok` | green | Yes |
| `fail` | red | Yes |
| `git` | purple | Yes |
| `node` | green | Yes |
| `rust` | red | Yes |
| `python` | yellow | Yes |
| `go` | cyan | Yes |
| `deno` | - | Yes |
| `bun` | - | Yes |
| `time` | - | Yes |

### Styles

**Colors**: `black`, `red`, `green`, `yellow`, `blue`, `purple`, `cyan`, `white`, `#hexcode`

**Modifiers**: `bold`, `dim`, `italic`, `underline`, `reverse`, `strikethrough`

Combine with dots: `cyan.bold`, `red.dim.italic`

**Background colors**: use `fg+bg` or `+bg` (background only), then modifiers.
Examples: `#ffffff+#333333`, `+blue`, `cyan+#222.dim`

### Escaping

- `\{` โ†’ `{` (literal brace)
- `\}` โ†’ `}` (literal brace)
- `\n` โ†’ newline
- `\t` โ†’ tab
- `\:` โ†’ `:` (literal colon in fields)
- `\\` โ†’ `\` (literal backslash)

## Performance

### Actual Response Times
| Scenario | Time | Notes |
|----------|------|-------|
| Path only | ~0.01ms | Minimal prompt |
| Path + Git | ~1-2ms | Branch and status |
| With Rust version | ~25-30ms | Includes `rustc --version` |
| With `--no-version` | <5ms | Skips all version detection |

### Benchmark Snapshot

| Scenario | Time (ยตs) | Notes |
|----------|-----------|-------|
| Minimal render | 0.69 | `{path}` only |
| Typical prompt | 1.71 | `{path} {git} {ok}{fail}` |
| Full prompt with versions | 4.90 | `{path} {git} {rust} {node}` |
| End-to-end (typical) | 2.53 | `prmt` binary execution |

> Measurements captured on an Intel Core i9-13900K host with project files on a SATA SSD (Rust 1.90.0 release build). Each value is the median of 100 `cargo bench` runs.

**Why is it fast?**
- Zero-copy parsing with SIMD optimizations
- Efficient memory allocation strategies
- Context-aware detection (only checks what's needed)
- No async operations or network calls
- Written in Rust for maximum performance

## Command-Line Options

```
prmt [OPTIONS] [FORMAT]

OPTIONS:
    -n, --no-version    Skip version detection for speed
    -d, --debug         Show debug information and timing
    -b, --bench         Run benchmark (100 iterations)
        --code <CODE>   Exit code of the last command (for ok/fail modules)
        --no-color      Disable colored output
    -h, --help         Print help
    -V, --version      Print version

ARGS:
    <FORMAT>           Format string (default from PRMT_FORMAT env var)
```

## Building from Source

```bash
# Requirements: Rust 2024 edition
git clone https://github.com/3axap4eHko/prmt.git
cd prmt
cargo build --release

# Run tests
cargo test

# Benchmark
./target/release/prmt --bench '{path} {rust} {git}'
```

## License

License [The MIT License](./LICENSE)
Copyright (c) 2025 Ivan Zakharchanka