Skip to content

Commit 54f7b90

Browse files
author
Buck Ryan
committed
Merge branch 'develop' into stdout-segment
2 parents b53337c + 7935d7a commit 54f7b90

File tree

5 files changed

+72
-53
lines changed

5 files changed

+72
-53
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 & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ python setup.py install
100100

101101
### Bash
102102

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

105105
```
106106
function _update_ps1() {
@@ -112,6 +112,8 @@ if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then
112112
fi
113113
```
114114

115+
**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`.
116+
115117
### ZSH
116118

117119
Add the following to your `.zshrc`:
@@ -172,42 +174,33 @@ powerline-shell --generate-config > ~/.powerline-shell.json
172174

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

212205
### Generic Segments
213206

@@ -318,6 +311,10 @@ The options for the `battery` segment are:
318311
- `always_show_percentage`: If true, show percentage when fully charged on AC.
319312
- `low_threshold`: Threshold percentage for low-battery indicator color.
320313

314+
The options for the `time` segment are:
315+
316+
- `format`: Format string as used by strftime function, e.g. `%H:%M`.
317+
321318
### Contributing new types of segments
322319

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

powerline_shell/__init__.py

Lines changed: 27 additions & 14 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,16 +216,24 @@ 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_conf in config["segments"]:
219229
if not isinstance(seg_conf, dict):
220230
seg_conf = {"type": seg_conf}
221-
module_name = "powerline_shell.segments." + seg_conf["type"]
222-
mod = importlib.import_module(module_name)
223-
segment = getattr(mod, "Segment")(powerline, seg_conf)
231+
seg_name = seg_conf["type"]
232+
seg_mod = custom_importer.import_(
233+
"powerline_shell.segments.",
234+
seg_name,
235+
"Segment")
236+
segment = getattr(seg_mod, "Segment")(powerline, seg_conf)
224237
segment.start()
225238
segments.append(segment)
226239
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)