Skip to content

jeffjose/twig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

twig

Fast shell prompt generator with daemon caching and multi-shell support.

Features

  • ANSI color and style support
  • Template-based configuration (TOML)
  • Daemon caching for expensive operations
  • Multi-shell output (TCSH, Bash, Zsh)
  • Implicit section creation
  • Environment variable expansion
  • Git branch display with graceful degradation

Installation

cargo build --release
cp target/release/twig ~/.local/bin/
cp target/release/twigd ~/.local/bin/

Usage

Development Mode

twig                    # Boxed output with timing

Shell Integration

twig --prompt           # Raw ANSI codes
twig --mode tcsh        # TCSH-specific format
twig --mode bash        # Bash-specific format
twig --mode zsh         # Zsh-specific format

Debugging

twig --mode tcsh --debug    # Show timing and config paths
TWIG_DEBUG=1 twig --mode tcsh  # Or use environment variable

Configuration

Default location: ~/.config/twig/config.toml

[prompt]
format = '''{time:cyan} {hostname:magenta} {cwd:green}
{"$":white,bold} '''

[time]
format = "%H:%M:%S"

Template Syntax

{variable}              # Plain variable
{variable:color}        # Colored variable
{variable:color,bold}   # Colored and styled
{"text":color}          # Literal colored text
{$ENV_VAR}              # Environment variable

Implicit Sections

Sections are created automatically based on template variables.

# Using {time} creates [time] section implicitly
# Using {hostname} creates [hostname] section implicitly
# Using {cwd} creates [cwd] section implicitly
# Using {git} creates [git] section implicitly

Override variable names:

[cwd]
name = "dir"  # Use {dir} instead of {cwd}

Git Support

Twig automatically displays the current git branch in your prompt!

[prompt]
format = '{time:cyan} {git:yellow} {cwd:green} {"$":white,bold} '

No additional configuration needed - it just works:

  • In a git repo: Shows current branch name
  • Outside a git repo: Shows nothing (graceful degradation)
  • Detached HEAD: Shows "HEAD"
  • Git not installed: Shows nothing (no errors in normal mode)

Validation Mode

Check if git is working correctly:

twig --validate

Output:

✓ All providers validated successfully

If git is not installed or there are issues, validation mode will show detailed errors.

Future Enhancements (not yet implemented):

  • Dirty status indicator (git_dirty)
  • Commits ahead/behind remote (git_ahead, git_behind)

Shell Setup

TCSH

# In ~/.tcshrc
set prompt="`twig --mode tcsh`"

Bash

# In ~/.bashrc
PS1=$(twig --mode bash)

Zsh

# In ~/.zshrc
PROMPT=$(twig --mode zsh)

Daemon

Start the caching daemon for faster prompts:

twigd &  # Runs in background, caches hostname

Cache location: ~/.local/share/twig/data.json

Colors

Basic: black, red, green, yellow, blue, magenta, cyan, white Bright: bright_red, bright_green, bright_blue, etc. Styles: bold, italic, underline

Architecture

twig/       CLI binary - generates prompts
twigd/      Daemon binary - caches expensive operations
docs/       Technical documentation
reference/  Example configurations

Documentation

  • docs/FEATURES.md - Complete feature list
  • docs/FEATURES-CHECKLIST.md - Development roadmap
  • docs/TCSH.md - TCSH implementation plan
  • docs/REFERENCE-mode-tcsh.md - TCSH technical reference

License

MIT

About

twig is a shell prompt

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages