From f3f13e998441fd9df4c106fd13c7b5f9cbfc02bb Mon Sep 17 00:00:00 2001 From: Wiktor Gonczaronek Date: Wed, 2 Oct 2019 11:21:14 +0200 Subject: [PATCH] Add custom indicator in root Users can define custom indicators in root segment. --- README.md | 4 ++++ powerline_shell/segments/root.py | 17 +++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e6295711..dca1a909 100644 --- a/README.md +++ b/README.md @@ -319,6 +319,10 @@ The options for the `time` segment are: - `format`: Format string as used by strftime function, e.g. `%H:%M`. +The options for the `root` segment are: + +- `indicator`: Set custom indicator, e.g. ` → `. + ### Contributing new types of segments The `powerline_shell/segments` directory contains python scripts which are diff --git a/powerline_shell/segments/root.py b/powerline_shell/segments/root.py index 7779eacf..dac91ee7 100644 --- a/powerline_shell/segments/root.py +++ b/powerline_shell/segments/root.py @@ -4,15 +4,20 @@ class Segment(BasicSegment): def add_to_powerline(self): powerline = self.powerline + indicator = self._get_indicator(powerline.args.shell, powerline) + bg = powerline.theme.CMD_PASSED_BG + fg = powerline.theme.CMD_PASSED_FG + if powerline.args.prev_error != 0: + fg = powerline.theme.CMD_FAILED_FG + bg = powerline.theme.CMD_FAILED_BG + powerline.append(indicator, fg, bg, sanitize=False) + + def _get_indicator(self, shell, powerline): + custom_indicator = powerline.segment_conf("root", "indicator", None) root_indicators = { 'bash': ' \\$ ', 'tcsh': ' %# ', 'zsh': ' %# ', 'bare': ' $ ', } - bg = powerline.theme.CMD_PASSED_BG - fg = powerline.theme.CMD_PASSED_FG - if powerline.args.prev_error != 0: - fg = powerline.theme.CMD_FAILED_FG - bg = powerline.theme.CMD_FAILED_BG - powerline.append(root_indicators[powerline.args.shell], fg, bg, sanitize=False) + return custom_indicator or root_indicators[shell]