Skip to content

Commit

Permalink
Add custom indicator in root
Browse files Browse the repository at this point in the history
Users can define custom indicators in root segment.
  • Loading branch information
wgonczaronek committed Oct 2, 2019
1 parent a9b8c9b commit 993f320
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions powerline_shell/segments/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 993f320

Please sign in to comment.