powerline-shell
Powerline-shell is a Python-based utility that generates a beautiful and highly customizable prompt for various shells including Bash, ZSH, Fish, and tcsh. It enhances the command-line experience by displaying contextual information such as version control status (Git, SVN, Mercurial), the current Python virtual environment, command exit codes, and a shortened current working directory. It is configured via a JSON file to define segments and themes. The current version is 0.7.0 and it is actively maintained.
Warnings
- breaking Powerline-shell requires Powerline-patched fonts (e.g., from powerline/fonts repository or Nerd Fonts) to display symbols (arrows, branch icons) correctly. Without them, you will see broken characters or squares.
- gotcha The order in which shell prompt commands (e.g., `_update_ps1` for Bash's `PROMPT_COMMAND`) are sourced can lead to unexpected behavior, such as incorrect exit codes or issues with certain segments.
- breaking The default location for `powerline-shell`'s configuration file changed to `~/.config/powerline-shell/config.json`. Older installations might look for configuration in different paths.
- gotcha While generally performant, complex segments or operations within very large or deeply nested version control repositories can occasionally introduce noticeable lag in prompt rendering.
Install
-
pip install powerline-shell -
git clone --depth=1 https://github.com/powerline/fonts.git cd fonts ./install.sh cd .. rm -rf fonts
Imports
- powerline_shell
powerline-shell is primarily configured via shell scripts and JSON files, not typically imported as a Python library for direct programmatic use. For extending it, segments are Python scripts located in powerline_shell/segments.
Quickstart
# 1. Install powerline-shell (if not already done)
pip install powerline-shell
# 2. Install Powerline-compatible fonts (if not already done)
# This is crucial for correct symbol rendering. Restart your terminal after installing.
git clone --depth=1 https://github.com/powerline/fonts.git
cd fonts
./install.sh
cd ..
rm -rf fonts
# 3. Configure your shell (example for Bash - add to ~/.bashrc)
# Find your powerline-shell.py path, e.g., using 'pip show powerline-shell' and looking at 'Location'
# Example path: $HOME/.local/bin/powerline-shell
# Ensure .local/bin is in PATH for pip-installed executables
export PATH="$PATH:$HOME/.local/bin"
function _update_ps1() {
PS1=$(powerline-shell $?)
}
if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi
# 4. Apply changes (or open a new terminal)
source ~/.bashrc
# 5. (Optional) Customize by copying the default config to your home directory
# and editing ~/.config/powerline-shell/config.json
mkdir -p ~/.config/powerline-shell
cp $(pip show powerline-shell | grep Location | cut -d ' ' -f 2)/powerline_shell/config.json.dist ~/.config/powerline-shell/config.json