A beautiful and useful prompt for your shell

Overview

A Powerline style prompt for your shell

A beautiful and useful prompt generator for Bash, ZSH, Fish, and tcsh:

MacVim+Solarized+Powerline+CtrlP

  • Shows some important details about the git/svn/hg/fossil branch (see below)
  • Changes color if the last command exited with a failure code
  • If you're too deep into a directory tree, shortens the displayed path with an ellipsis
  • Shows the current Python virtualenv environment
  • It's easy to customize and extend. See below for details.

The generated prompts are designed to resemble powerline, but otherwise this project has no relation to powerline.

Table of Contents generated with DocToc

Version Control

All of the version control systems supported by powerline shell give you a quick look into the state of your repo:

  • The current branch is displayed and changes background color when the branch is dirty.
  • When the local branch differs from the remote, the difference in number of commits is shown along with or indicating whether a git push or pull is pending.

If files are modified or in conflict, the situation is summarized with the following symbols:

  • -- a file has been modified (but not staged for commit, in git)
  • -- a file is staged for commit (git) or added for tracking
  • -- a file has conflicts
  • ? -- a file is untracked

Each of these will have a number next to it if more than one file matches.

The segment can start with a symbol representing the version control system in use. To show that symbol, the configuration file must have a variable vcs with an option show_symbol set to true (see Segment Configuration).

Setup

This script uses ANSI color codes to display colors in a terminal. These are notoriously non-portable, so may not work for you out of the box, but try setting your $TERM to xterm-256color.

  • Patch the font you use for your terminal: see powerline-fonts

    • If you struggle too much to get working fonts in your terminal, you can use "compatible" mode.
    • If you're using old patched fonts, you have to use the older symbols. Basically reverse this commit in your copy.
  • Install using pip:

pip install powerline-shell

(You can use the --user option to install for just your user, if you'd like. But you may need to fiddle with your PATH to get this working properly.)

  • Or, install from the git repository:
git clone https://github.com/b-ryan/powerline-shell
cd powerline-shell
python setup.py install
  • Setup your shell prompt using the instructions for your shell below.

Bash

Add the following to your .bashrc file:

function _update_ps1() {
    PS1=$(powerline-shell $?)
}

if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi

Note: On macOS, you must add this to one of .bash_profile, .bash_login, or .profile. macOS will execute the files in the aforementioned order and will stop execution at the first file it finds. For more information on the order of precedence, see the section INVOCATION in man bash.

ZSH

Add the following to your .zshrc:

function powerline_precmd() {
    PS1="$(powerline-shell --shell zsh $?)"
}

function install_powerline_precmd() {
  for s in "${precmd_functions[@]}"; do
    if [ "$s" = "powerline_precmd" ]; then
      return
    fi
  done
  precmd_functions+=(powerline_precmd)
}

if [ "$TERM" != "linux" ]; then
    install_powerline_precmd
fi

Fish

Redefine fish_prompt in ~/.config/fish/config.fish:

function fish_prompt
    powerline-shell --shell bare $status
end

tcsh

Add the following to your .tcshrc:

alias precmd 'set prompt="`powerline-shell --shell tcsh $?`"'

Customization

Config File

Powerline-shell is customizable through the use of a config file. This file is expected to be located at ~/.config/powerline-shell/config.json. You can generate the default config at this location using:

mkdir -p ~/.config/powerline-shell && \
powerline-shell --generate-config > ~/.config/powerline-shell/config.json

(As an example, my config file is located here: here)

Adding, Removing and Re-arranging segments

Once you have generated your config file, you can now start adding or removing "segments" - the building blocks of your shell. The list of segments available can be seen here.

You can also create custom segments. Start by copying an existing segment like this. Make sure to change any relative imports to absolute imports. Ie. change things like:

from ..utils import BasicSegment

to

from powerline_shell.utils import BasicSegment

Then change the add_to_powerline function to do what you want. You can then use this segment in your configuration by putting the path to your segment in the segments section, like:

"segments": [
    "~/path/to/segment.py"
]

Generic Segments

There are two special segments available. stdout accepts an arbitrary command and the output of the command will be put into your prompt. env takes an environment variable and the value of the variable will be set in your prompt. For example, your config could look like this:

{
  "segments": [
    "cwd",
    "git",
    {
      "type": "stdout",
      "command": ["echo", "hi"],
      "fg_color": 22,
      "bg_color": 161
    },
    {
      "type": "env",
      "var": "DOCKER_MACHINE_NAME",
    },
  ]
}

Segment Separator

By default, a unicode character (resembling the > symbol) is used to separate each segment. This can be changed by changing the "mode" option in the config file. The available modes are:

  • patched - The default.
  • compatible - Attempts to use characters that may already be available using your chosen font.
  • flat - No separator is used between segments, giving each segment a rectangular appearance (and also saves space).

Themes

The powerline_shell/themes directory stores themes for your prompt, which are basically color values used by segments. The default.py defines a default theme which can be used standalone, and every other theme falls back to it if they miss colors for any segments.

If you want to create a custom theme, start by copying one of the existing themes, like the basic. and update your ~/.config/powerline-shell/config.json, setting the "theme" to the path of the file. For example your configuration might have:

  "theme": "~/mythemes/my-great-theme.py"

You can then modify the color codes to your liking. Theme colors are specified using Xterm-256 color codes.

A script for testing color combinations is provided at colortest.py. Note that the colors you see may vary depending on your terminal. When designing a theme, please test your theme on multiple terminals, especially with default settings.

Segment Configuration

Some segments support additional configuration. The options for the segment are nested under the name of the segment itself. For example, all of the options for the cwd segment are set in ~/.config/powerline-shell/config.json like:

{
    "segments": [...],
    "cwd": {
        options go here
    }
    "theme": "theme-name",
    "vcs": {
        options go here
    }
}

The options for the cwd segment are:

  • mode: If plain, then simple text will be used to show the cwd. If dironly, only the current directory will be shown. Otherwise expands the cwd into individual directories.
  • max_depth: Maximum number of directories to show in path.
  • max_dir_size: Maximum number of characters displayed for each directory in the path.
  • full_cwd: If true, the last directory will not be shortened when max_dir_size is used.

The hostname segment provides one option:

  • colorize: If true, the hostname will be colorized based on a hash of itself.

The vcs segment provides one option:

  • show_symbol: If true, the version control system segment will start with a symbol representing the specific version control system in use in the current directory.

The options for the battery segment are:

  • always_show_percentage: If true, show percentage when fully charged on AC.
  • low_threshold: Threshold percentage for low-battery indicator color.

The options for the time segment are:

  • format: Format string as used by strftime function, e.g. %H:%M.

Contributing new types of segments

The powerline_shell/segments directory contains python scripts which are injected as is into a single file powerline_shell_base.py. Each segment script defines a function that inserts one or more segments into the prompt. If you want to add a new segment, simply create a new file in the segments directory.

Make sure that your script does not introduce new globals which might conflict with other scripts. Your script should fail silently and run quickly in any scenario.

Make sure you introduce new default colors in themes/default.py for every new segment you create. Test your segment with this theme first.

You should add tests for your segment as best you are able. Unit and integration tests are both welcome. Run your tests by running the test.sh script. It uses docker to manage dependencies and the environment. Alternatively, you can run the nosetests command after installing the requirements in requirements-dev.txt.

Troubleshooting

See the FAQ. If you continue to have issues, please open an issue.

Comments
  • rxvt-unicode-256color powerline-shell issue no " was displayed">

    rxvt-unicode-256color powerline-shell issue no ">" was displayed

    rxvt-unicode-9.21-3.fc21.x86_64
    rxvt-unicode-256color-9.21-3.fc21.x86_64
    

    Detail please check this pic as below: https://imagebin.ca/v/2ctVBFcLxuy1

    Could anybody tell me what is going wrong ? Thanks !

    opened by bluezd 23
  • Directories not being shortened under Windows 10 GitBash

    Directories not being shortened under Windows 10 GitBash

    untitled

    Here's my config:

    {
        "segments": [
            "time",
            "git",
            "set_term_title",
            "cwd",
            "newline",
            "virtual_env",
            "exit_code",
            "username",
            "root"
        ],
        "hostname": {"colorize":"true"},
        "cwd": {
            "mode": "plain",
            "max_depth": 4,
            "full_cwd": "true",
            "max_dir_size": -1
        },
        "theme": "solarized_light",
        "mode":"patched" 
    }
    

    Python version is 3.6.4, just pulled powerline-shell from PyPI.

    opened by nick5435 20
  • Feature/gitsegment

    Feature/gitsegment

    Hello, This branch enhances the git segment with detailed "git status" overview in the prompt.

    • Number of commits behind remote tracking branch
    • Number of commits ahead remote tracking branch
    • Number of untracked files
    • Number of files staged for commit
    • Number of files modified but not staged for commit
    • Number of conflicted files
    • I've improved the detached head mode: currently, when in detached head mode, if there is a tag which describe this commit, the name of the tag is display instead of the sha1. Otherwise, if there is no tag describing HEAD, the sha1 is displayed.
    • I've chosen UTF-8 characters for each info.

    For the prompt to still be fast, I tried my best to minimize the number of shell commands launched. In your version, 2 git processes are launched, in my version, I succeed to keep the same number: I only launch 2 git subprocesses, but there is much more info displayed.

    I still don't like the default color I chose for "modified but not staged for commit". Do you have a better idea?

    This is the longest prompt possible: gitsegment_demo

    • The HEAD is detached, and since no tag describes this commit, the sha1 is printed, along with an anchor UTF8 character.
    • There are 2 files staged for commit
    • The are 3 files modified but not stagged for commit
    • There is 1 untracked file
    • There is 1 conflicted file (unmerged).
    opened by mwetterw 19
  • VCS symbols

    VCS symbols

    Taking on @mislam's PR #170, I adapted it to the current state of the VCS' segments.

    In the meanwhile I've noticed that the svn segment wasn't working properly and was implemented as a basic segment, so I decided to reimplement it as a threaded one. I should have used a separate branch for this but figured that it wouldn't be worth the trouble. I'll probably implement the svn tests later on, though, and for that I'll use a separate branch + PR, of course.

    opened by emansije 16
  • How to use powerline with pyenv-virtualenv?

    How to use powerline with pyenv-virtualenv?

    I upgraded from something very old to recent powerline

    But now when I do pyenv activate myenv my prompt dies because powerline is not installed in the virtualenv

    Is there a workaround for this?

    opened by anentropic 14
  • Sometimes PowerLine doesn't show up

    Sometimes PowerLine doesn't show up

    Hi ! Sometimes when I open the terminal PowerShell doesn't show up and I'm stuck with this screen : plbug

    But I can execute some commands : plbug

    Re-open the terminal doesn't solve the problem, the only way I found to solve this is to restart my computer but I'm sure there's an easier way to fix that.. What can we do about this ?

    P.S: This problem happens with fish and bash, so I don't think the problem is related to this...

    Thank you !

    opened by yvgny 14
  • Showing + Sign and Red Background when Git working directory clean

    Showing + Sign and Red Background when Git working directory clean

    I've been working on a git repo and after some changes and pushes I always see a + (plus) sign with a red background on the git segment even tough git status tells me:

    # On branch whatever
    nothing to commit, working directory clean
    
    opened by LeonardoGentile 13
  • exit code segment has never worked for me

    exit code segment has never worked for me

    I have never seen the prompt change color when last command had non zero exit code. I have enabled the segment in config always. Do I need to do something more?

    opened by shikhanshu 12
  • Split line

    Split line

    I would like the prompt to start on a new line. I added a regular newline character, but then I get this result:

    powerline

    It's a small beauty problem, but it really annoys me.

    opened by skerit 12
  • Add Bazaar segment

    Add Bazaar segment

    This is based on PR #162 from @1stvamp. His fork seems to be stalled, so I decided to do my own and implement the segment following the current style of the code. I'm not sure if there was a better procedure, but let me know, if that's the case, and I'll follow the instructions.

    opened by emansije 11
  • short dir listing for cwd

    short dir listing for cwd

    The documentation is completely confusing to me with regards to how I would use ~/.powerline-shell.py to set up short dir listings for the current working directory. What I would like to do is have only the first letter of each directory displayed except for the current directory which should be the full name. Documentation indicates this is possible using something like the bottom, but I'm totally confused as to how this is done. The documentation completely fails to describe how I actually do this.

    #powerline.segments.common.env.cwd(dir_shorten_len=1)

    opened by jceaser 10
  • Add option to require package.json for node_version segment

    Add option to require package.json for node_version segment

    I added some features to the node_version segment to make it more configurable and fit my needs better.

    Configuration Variables

    If "requires_package" is set to true, then the segment will not add the segment if it does not find a "package.json" file in the path to the root. I also added "chars" which is the number of characters of the output of node --version to display.

    Example Configuration:

    {
      "segments": [
        "node_version"
      ],
      "node_version": {
          "require_package": true,
          "chars": 3
      }
    }
    

    Default

    image

    With "chars": 3

    image

    opened by maxrzaw 0
  • powerline-shell prints out ansi sequences instead of color

    powerline-shell prints out ansi sequences instead of color

    So I installed powerline-shell via the git way, everything seems to be working normally when I hit powerline-shell and it prints out this junk:

    powerline-shell --shell bash
    \[\e[38;5;250m\]\[\e[48;5;240m\] \u \[\e[48;5;238m\]\[\e[38;5;240m\]\[\e[38;5;250m\]\[\e[48;5;238m\] \h \[\e[48;5;31m\]\[\e[38;5;238m\]\[\e[38;5;15m\]\[\e[48;5;31m\] ~ \[\e[48;5;236m\]\[\e[38;5;31m\]\[\e[38;5;15m\]\[\e[48;5;236m\] \$ \[\e[0m\]\[\e[38;5;236m\]\[\e[0m\] <imyusername>
    

    Powerline works normally on my terminal(s). How can I fix this?

    opened by ducmatgoctoanlyhoa 2
  • Run with specific theme/color givin via commandline option

    Run with specific theme/color givin via commandline option

    I am "running" my powerline-shell from ~/.bash_aliases (Debian 11).

    if tty | grep -q '/dev/pts'; then
        powerline-daemon -q
        POWERLINE_BASH_CONTINUATION=1
        POWERLINE_BASH_SELECT=1
        . /usr/share/powerline/bindings/bash/powerline.sh
    fi
    

    I am sharing this .bash_aliases on different machines. I want to use different powerline themes for different machines. I would check for that machines in that .bash_aliases file. Is there a way run the powerline.sh script with a specific theme/color?

    opened by buhtz 0
  • bash-setup: missing explanation

    bash-setup: missing explanation

    This is about this section of your documentation https://github.com/b-ryan/powerline-shell#bash

    The bash code is without in-line comments. The text before the code does not explain the code. So it is unclear what the code does. Bash is not self explaining.

    It would improve the documentation if you could add one or two short sentences about what this code does. Thank you very much.

    opened by buhtz 0
  • Use default terminal colors

    Use default terminal colors

    Hello,

    I use Konsole and it already have a color scheme customization. My question is, is there a way for me to keep the color scheme defined in Konsole (and other terminal emulators) instead of using the ones defined on the themes files?

    opened by gabriel-lima96 0
Owner
Buck Ryan
Buck Ryan
Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source.

Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source. Getting Started This is an example of ho

null 14 Apr 10, 2022
A Sophisticated And Beautiful Doxing Tool

Garuda V1.1 A Sophisticated And Beautiful Doxing Tool Works on Android[Termux] | Linux | Windows Don't Forget to give it a star ❗ How to use ❓ First o

The Cryptonian 67 Jan 10, 2022
This python code will get requests from SET (The Stock Exchange of Thailand) a previously-close stock price and return it in Thai Baht currency using beautiful soup 4 HTML scrapper.

This python code will get requests from SET (The Stock Exchange of Thailand) a previously-close stock price and return it in Thai Baht currency using beautiful soup 4 HTML scrapper.

Andre 1 Oct 24, 2022
A very small (15 lines of code) and beautiful fetch script (exclusively for Arch Linux).

minifetch A very small (15 lines of code) and beautiful fetch script (exclusively for Arch Linux). There are many fetch scripts out there but I wanted

null 16 Jul 11, 2022
Badge-Link-Creater 'For more beautiful profiles.'

Badge-Link-Creater 'For more beautiful profiles.' Ready Badges Prepares the codes of the previously prepared badges for you. Note Click here for more

Mücahit Gündüz 9 Oct 19, 2022
Utility/Raiding selfbot made by Shell and Roover.

Utility/Raiding selfbot made by Shell and Roover. We are open to suggestions and ideas.

Shell 2 Dec 8, 2021
Improve current data preprocessing for FTM's WOB data to analyze Shell and Dutch Governmental contacts.

We're the hackathon leftovers, but we are Too Good To Go ;-). A repo by Lukas Schubotz and Raymon van Dinter. We aim to improve current data preprocessing for FTM's WOB data to analyze Shell and Dutch Governmental contacts.

ASReview hackathon for Follow the Money 5 Dec 9, 2021
Information about a signed UEFI Shell that can be used when Secure Boot is enabled.

SignedUEFIShell During our research of the BootHole vulnerability last year, we tried to find as many signed bootloaders as we could. We searched all

Mickey 61 Jan 3, 2023
Shell scripts made simple 🐚

zxpy Shell scripts made simple ?? Inspired by Google's zx, but made much simpler and more accessible using Python. Rationale Bash is cool, and it's ex

Tushar Sadhwani 492 Dec 27, 2022
Penelope Shell Handler

penelope Penelope is an advanced shell handler. Its main aim is to replace netcat as shell catcher during exploiting RCE vulnerabilities. It works on

null 293 Dec 30, 2022
A server shell for you to play with Powered by Django + Nginx + Postgres + Bootstrap + Celery.

A server shell for you to play with Powered by Django + Nginx + Postgres + Bootstrap + Celery.

Mengting Song 1 Jan 10, 2022
Shell Trality API for local development.

Trality Simulator Intro This package is a work in progress. It allows local development of Trality bots in an IDE such as VS Code. The package provide

CrypTrality 1 Nov 17, 2021
The purpose of this script is to bypass disablefund, provide some useful information, and dig the hook function of PHP extension.

The purpose of this script is to bypass disablefund, provide some useful information, and dig the hook function of PHP extension.

Firebasky 14 Aug 2, 2021
A project to explore and provide useful code for Mango Markets

?? Mango Explorer A project to explore and provide useful code for Mango Markets

Blockworks Foundation 160 Dec 19, 2022
Repository, with small useful and functional applications

Repositorio,com pequenos aplicativos uteis e funcionais A ideia e ir deselvolvendo pequenos aplicativos funcionais e adicionar a este repositorio List

GabrielDuke 6 Dec 6, 2021
Blender addon that simplifies access to useful operators and adds missing functionality

Quick Menu is a Blender addon that simplifies common tasks Compatible with Blender 3.x.x Install through Edit -> Preferences -> Addons -> Install... -

passivestar 94 Dec 27, 2022
A code base for python programs the goal is to integrate all the useful and essential functions

Base Dev EN This GitHub will be available in French and English FR Ce GitHub sera disponible en français et en anglais Author License Screen EN ???? D

Pikatsuto 1 Mar 7, 2022
A repository containing useful resources needed to complete the SUSE Scholarship Challenge #UdacitySUSEScholars #poweredbySUSE

SUSE-udacity-cloud-native-scholarship A repository containing useful resources needed to complete the SUSE Scholarship Challenge #UdacitySUSEScholars

Nandini Proothi 11 Dec 2, 2021
Additional useful operations for Python

Pyteal Extensions Additional useful operations for Python Available Operations MulDiv64: calculate m1*m2/d with no overflow on multiplication (TEAL 3+

Ulam Labs 11 Dec 14, 2022