Skip to content

Custom indicators on root segment #406

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

Open
wants to merge 2 commits 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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,19 @@ 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 `root` segment provides the option to customize `indicators` on each of the supported shells. For example:

```
{
"root": {
"indicators": {
"bash": " bash 🤖 ",
"zsh": " zsh 🤖 "
}
}
}
```

### Contributing new types of segments

The `powerline_shell/segments` directory contains python scripts which are
Expand Down
19 changes: 15 additions & 4 deletions powerline_shell/segments/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
class Segment(BasicSegment):
def add_to_powerline(self):
powerline = self.powerline
config = self.powerline.config

def exists(obj, chain):
_key = chain.pop(0)
if _key in obj:
return exists(obj[_key], chain) if chain else obj[_key]

def indicators(default, shell, path='root.indicators'):
indicator = exists(config, (path + '.' + shell).split('.'))
return indicator if indicator else default

root_indicators = {
'bash': ' \\$ ',
'tcsh': ' %# ',
'zsh': ' %# ',
'bare': ' $ ',
'bash': indicators(' \\$ ', 'bash'),
'tcsh': indicators(' %# ', 'tcsh'),
'zsh': indicators(' %# ', 'zsh'),
'bare': indicators(' $ ', 'bare'),
}
bg = powerline.theme.CMD_PASSED_BG
fg = powerline.theme.CMD_PASSED_FG
Expand Down