Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom indicator in root #479

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]