Skip to content

Commit 3d46c13

Browse files
authored
Merge pull request #416 from b-ryan/develop
Develop
2 parents 3b95178 + 7935d7a commit 3d46c13

File tree

5 files changed

+71
-50
lines changed

5 files changed

+71
-50
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes
22

3+
Unreleased (version 0.6.0)
4+
5+
* Support for custom themes
6+
* New option for the `time` segment to specify format of the displayed time
7+
([@dundalek](https://github.com/b-ryan/powerline-shell/pull/383))
8+
39
2018-04-22 (version 0.5.4)
410

511
* Reverted fix for

README.md

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ python setup.py install
9898

9999
### Bash
100100

101-
Add the following to your `.bashrc` (or `.profile` on Mac):
101+
Add the following to your `.bashrc` file:
102102

103103
```
104104
function _update_ps1() {
@@ -110,6 +110,8 @@ if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then
110110
fi
111111
```
112112

113+
**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`.
114+
113115
### ZSH
114116

115117
Add the following to your `.zshrc`:
@@ -171,40 +173,33 @@ powerline-shell --generate-config > ~/.config/powerline-shell/config.json
171173

172174
Once you have generated your config file, you can now start adding or removing
173175
"segments" - the building blocks of your shell. The list of segments available
174-
are:
175-
176-
- `aws_profile` - Show which AWS profile is in use. See the
177-
[AWS](http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html)
178-
documentation.
179-
- `battery` - See percentage of battery charged and an icon when the battery is
180-
charging.
181-
- `bzr` - Details about the current Bazaar repo.
182-
- `cwd` - Shows your current working directory. See [Segment
183-
Configuration](#segment-configuration) for some options.
184-
- `exit_code` - When the previous command ends in a non-zero status, shows the
185-
value of the exit status in red.
186-
- `fossil` - Details about the current Fossil repo.
187-
- `git` - Details about the current Git repo.
188-
- `git_stash` - Number of stashes in the current Git repo.
189-
- `hg` - Details about the current Mercurial repo.
190-
- `hostname` - Current machine's hostname.
191-
- `jobs` - Number of background jobs currently running.
192-
- `newline` - Inserts a newline into the prompt.
193-
- `node_version` - `node --version`
194-
- `npm_version` - `npm --version`
195-
- `php_version` - Version of php on the machine.
196-
- `rbenv` - `rbenv local`
197-
- `read_only` - Shows a lock icon if the current directory is read-only.
198-
- `root` - Shows a `#` if logged in as root, `$` otherwise.
199-
- `ruby_version` - `ruby --version`
200-
- `set_term_title` - If able, sets the title of your terminal to include some
201-
useful info.
202-
- `ssh` - If logged into over SSH, shows a network icon.
203-
- `svn` - Details about the current SVN repo.
204-
- `time` - Shows the current time.
205-
- `uptime` - Uptime of the current machine.
206-
- `username` - Name of the logged-in user.
207-
- `virtual_env` - Shows the name of the current virtual env or conda env.
176+
can be seen
177+
[here](https://github.com/b-ryan/powerline-shell/tree/master/powerline_shell/segments).
178+
179+
You can also create custom segments. Start by copying an existing segment like
180+
[this](https://github.com/b-ryan/powerline-shell/blob/master/powerline_shell/segments/aws_profile.py).
181+
Make sure to change any relative imports to absolute imports. Ie. change things
182+
like:
183+
184+
```python
185+
from ..utils import BasicSegment
186+
```
187+
188+
to
189+
190+
```python
191+
from powerline_shell.utils import BasicSegment
192+
```
193+
194+
Then change the `add_to_powerline` function to do what you want. You can then
195+
use this segment in your configuration by putting the path to your segment in
196+
the segments section, like:
197+
198+
```json
199+
"segments": [
200+
"~/path/to/segment.py"
201+
]
202+
```
208203

209204
### Segment Separator
210205

@@ -289,6 +284,10 @@ The options for the `battery` segment are:
289284
- `always_show_percentage`: If true, show percentage when fully charged on AC.
290285
- `low_threshold`: Threshold percentage for low-battery indicator color.
291286

287+
The options for the `time` segment are:
288+
289+
- `format`: Format string as used by strftime function, e.g. `%H:%M`.
290+
292291
### Contributing new types of segments
293292

294293
The `powerline_shell/segments` directory contains python scripts which are

powerline_shell/__init__.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,26 @@ def find_config():
167167
}
168168

169169

170-
class ThemeNotFoundException(Exception):
170+
class ModuleNotFoundException(Exception):
171171
pass
172172

173173

174-
def read_theme(config):
175-
theme_name = config.get("theme", "default")
176-
try:
177-
mod = importlib.import_module("powerline_shell.themes." + theme_name)
178-
except ImportError:
174+
class CustomImporter(object):
175+
def __init__(self):
176+
self.file_import_count = 0
177+
178+
def import_(self, module_prefix, module_or_file, description):
179179
try:
180-
mod = import_file("custom_theme", os.path.expanduser(theme_name))
180+
mod = importlib.import_module(module_prefix + module_or_file)
181181
except ImportError:
182-
raise ThemeNotFoundException(
183-
"Theme " + theme_name + " cannot be found")
184-
return getattr(mod, "Color")
182+
try:
183+
module_name = "_custom_mod_{0}".format(self.file_import_count)
184+
mod = import_file(module_name, os.path.expanduser(module_or_file))
185+
self.file_import_count += 1
186+
except (ImportError, IOError):
187+
msg = "{0} {1} cannot be found".format(description, module_or_file)
188+
raise ModuleNotFoundException( msg)
189+
return mod
185190

186191

187192
def main():
@@ -211,13 +216,21 @@ def main():
211216
else:
212217
config = DEFAULT_CONFIG
213218

214-
theme = read_theme(config)
219+
custom_importer = CustomImporter()
220+
theme_mod = custom_importer.import_(
221+
"powerline_shell.themes.",
222+
config.get("theme", "default"),
223+
"Theme")
224+
theme = getattr(theme_mod, "Color")
215225

216226
powerline = Powerline(args, config, theme)
217227
segments = []
218228
for seg_name in config["segments"]:
219-
mod = importlib.import_module("powerline_shell.segments." + seg_name)
220-
segment = getattr(mod, "Segment")(powerline)
229+
seg_mod = custom_importer.import_(
230+
"powerline_shell.segments.",
231+
seg_name,
232+
"Segment")
233+
segment = getattr(seg_mod, "Segment")(powerline)
221234
segment.start()
222235
segments.append(segment)
223236
for segment in segments:

powerline_shell/segments/time.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
class Segment(BasicSegment):
77
def add_to_powerline(self):
88
powerline = self.powerline
9-
if powerline.args.shell == 'bash':
9+
format = powerline.segment_conf('time', 'format')
10+
if format:
11+
time_ = ' %s ' % time.strftime(format)
12+
elif powerline.args.shell == 'bash':
1013
time_ = ' \\t '
1114
elif powerline.args.shell == 'zsh':
1215
time_ = ' %* '

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="powerline-shell",
6-
version="0.5.4",
6+
version="0.6.0",
77
description="A pretty prompt for your shell",
88
author="Buck Ryan",
99
author_email="buck@buckryan.com",

0 commit comments

Comments
 (0)