A simple powerline-like shell prompt generator written in C. It strives to be fast (light) and portable.
# edit config.h and main.c if you want
make
make install
PS1='$(pwrln $?)'
To generate prompt for specific shell append its name delimited by -
to pwrln
executable name e.g. pwrln-bash
, pwrln-ksh
, ...
# rename pwrln binary
mv pwrln pwrln-ksh
# or create symlink
ln -s pwrln pwrln-ksh
make install
creates symlinks for all supported shells.
Shell support
Generating prompt for specific shell boils down to applying proper
escape code delimiters, so that its input line editor (e.g. readline
)
takes into account only printable characters when estimating prompt
length.
Shells recognised by pwrln
so far:
- bash
- ksh
- zsh
- rc (readline)
before adding entries to your shell config adjust the code to your liking (see Customisation) and install it with:
% make
# make install
bash
Add those lines to .bashrc
:
PS1='$(pwrln-bash $?)'
export PS1
Notice '
single-quote marks.
ksh
Roughly the same case as with bash.
Add those lines to .kshrc
or .mkshrc
or .profile
or whatever:
PS1='$(pwrln-ksh $?)'
export PS1
Notice '
single-quote marks.
zsh
Add those lines to .zshrc
:
precmd()
{
export PROMPT="$(pwrln-zsh $?)"
}
rc
Add those lines to .rcrc
:
fn prompt {
_status = $status
PWD = `pwd
_prompt = `{pwrln-rc $_status}
prompt = $^_prompt' '
}
Customisation
Change colours and glyphs (special characters) in config.h
.
If your font does not display fancy characters like that powerline arrow you might replace them with any string (e.g. empty string):
static const char glyph_delimiter[] = "";
static const char glyph_subdelimiter[] = ">";
In main.c
a linked list of elements representing prompt
segments is assembled.
Those segments can be swapped, removed etc.
Creating custom segments is straightforward:
/* font colour -------------+
background colour -----+ |
| | */
tail(prompt_chain)->next = new("my custom segment", 238, 248);
/* tail(first_segment) returns last segment in chain */