Skip to content

Commit b53337c

Browse files
author
Buck Ryan
committed
Merge branch 'develop' into stdout-segment
2 parents 47ca2df + 73b01d6 commit b53337c

30 files changed

+457
-127
lines changed

CHANGELOG.md

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

3+
2018-04-22 (version 0.5.4)
4+
5+
* Reverted fix for
6+
([#249](https://github.com/b-ryan/powerline-shell/issues/249)) because it
7+
caused issues on Mac.
8+
9+
2018-04-21 (version 0.5.3)
10+
11+
* New theme! (gruvbox)
12+
([@monicaycli](https://github.com/b-ryan/powerline-shell/pull/388))
13+
14+
2018-04-21 (version 0.5.2)
15+
16+
* Fix hostname colorize bug
17+
([@comagnaw](https://github.com/b-ryan/powerline-shell/issues/353))
18+
* Fix issue with prompt bleeding behavior
19+
([@bytebeast](https://github.com/b-ryan/powerline-shell/issues/249))
20+
* Better error message when config file cannot be decoded (Closes
21+
[#371](https://github.com/b-ryan/powerline-shell/issues/371))
22+
23+
2018-04-13 (version 0.5.1)
24+
25+
* Fix Python 3 compatibility of `git_stash` segment
26+
27+
2018-04-10 (version 0.5.0)
28+
29+
* Patch environment for VCS subprocesses rather than generating a new one
30+
* Fix `cwd` segment so it respects `max_depth` configuration
31+
* Fix Ruby segment for Python 3 compatibility
32+
([@Blue-Dog-Archolite](https://github.com/b-ryan/powerline-shell/pull/366))
33+
* Configuration is now expected to be at
34+
`~/.config/powerline-shell/config.json` ([@emansije and
35+
@kc9jud](https://github.com/b-ryan/powerline-shell/pull/334))
36+
* New `git_stash` segment
37+
([@apinkney97](https://github.com/b-ryan/powerline-shell/pull/379))
38+
39+
2018-02-19 (version 0.4.9)
40+
41+
* Fix root user segment
42+
([@TiGR](https://github.com/b-ryan/powerline-shell/pull/362))
43+
* Fixes and enhancements for SVN segment
44+
([@emansije](https://github.com/b-ryan/powerline-shell/pull/349))
45+
346
2018-01-29 (version 0.4.8)
447

548
* Bring back the ability to create custom themes

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# A Powerline style prompt for your shell
22

3-
A [Powerline](https://github.com/Lokaltog/vim-powerline) like prompt for Bash,
4-
ZSH, Fish, and tcsh:
3+
A beautiful and useful prompt generator for Bash, ZSH, Fish, and tcsh:
54

6-
![MacVim+Solarized+Powerline+CtrlP](https://raw.github.com/banga/powerline-shell/master/bash-powerline-screenshot.png)
5+
![MacVim+Solarized+Powerline+CtrlP](https://raw.github.com/b-ryan/powerline-shell/master/bash-powerline-screenshot.png)
76

87
- Shows some important details about the git/svn/hg/fossil branch (see below)
98
- Changes color if the last command exited with a failure code
109
- If you're too deep into a directory tree, shortens the displayed path with an ellipsis
1110
- Shows the current Python [virtualenv](http://www.virtualenv.org/) environment
1211
- It's easy to customize and extend. See below for details.
1312

13+
The generated prompts are designed to resemble
14+
[powerline](https://github.com/powerline/powerline), but otherwise this project
15+
has no relation to powerline.
16+
1417
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1518
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1619
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
@@ -50,7 +53,7 @@ following symbols:
5053
- `` -- a file has been modified (but not staged for commit, in git)
5154
- `` -- a file is staged for commit (git) or added for tracking
5255
- `` -- a file has conflicts
53-
- `` -- a file is untracked
56+
- `?` -- a file is untracked
5457

5558
Each of these will have a number next to it if more than one file matches.
5659

@@ -63,7 +66,7 @@ with an option `show_symbol` set to `true` (see
6366

6467
This script uses ANSI color codes to display colors in a terminal. These are
6568
notoriously non-portable, so may not work for you out of the box, but try
66-
setting your $TERM to `xterm-256color`, because that works for me.
69+
setting your $TERM to `xterm-256color`.
6770

6871
- Patch the font you use for your terminal: see
6972
[powerline-fonts](https://github.com/Lokaltog/powerline-fonts)
@@ -88,7 +91,7 @@ install for just your user, if you'd like. But you may need to fiddle with your
8891
- Or, install from the git repository:
8992

9093
```
91-
git clone https://github.com/banga/powerline-shell
94+
git clone https://github.com/b-ryan/powerline-shell
9295
cd powerline-shell
9396
python setup.py install
9497
```
@@ -155,14 +158,14 @@ alias precmd 'set prompt="`powerline-shell --shell tcsh $?`"'
155158
### Config File
156159

157160
Powerline-shell is customizable through the use of a config file. This file is
158-
expected to be located at `~/.powerline-shell.json`. You can generate the
159-
default config at this location using:
161+
expected to be located at `~/.config/powerline-shell/config.json`. You can
162+
generate the default config at this location using:
160163

161164
```
162165
powerline-shell --generate-config > ~/.powerline-shell.json
163166
```
164167

165-
(You can see an example config file
168+
(As an example, my config file is located here:
166169
[here](https://github.com/b-ryan/dotfiles/blob/master/home/powerline-shell.json))
167170

168171
### Adding, Removing and Re-arranging segments
@@ -184,6 +187,7 @@ are:
184187
- `env` - See [Generic Segments](#generic-segments)
185188
- `fossil` - Details about the current Fossil repo.
186189
- `git` - Details about the current Git repo.
190+
- `git_stash` - Number of stashes in the current Git repo.
187191
- `hg` - Details about the current Mercurial repo.
188192
- `hostname` - Current machine's hostname.
189193
- `jobs` - Number of background jobs currently running.
@@ -337,6 +341,6 @@ requirements in `requirements-dev.txt`.
337341

338342
## Troubleshooting
339343

340-
See the [FAQ](https://github.com/banga/powerline-shell/wiki/FAQ). If you
344+
See the [FAQ](https://github.com/b-ryan/powerline-shell/wiki/FAQ). If you
341345
continue to have issues, please open an
342-
[issue](https://github.com/banga/powerline-shell/issues/new).
346+
[issue](https://github.com/b-ryan/powerline-shell/issues/new).

powerline_shell/__init__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ def fgcolor(self, code):
114114
def bgcolor(self, code):
115115
return self.color('48', code)
116116

117-
def append(self, content, fg, bg, separator=None, separator_fg=None):
117+
def append(self, content, fg, bg, separator=None, separator_fg=None, sanitize=True):
118+
if self.args.shell == "bash" and sanitize:
119+
content = re.sub(r"([`$])", r"\\\1", content)
118120
self.segments.append((content, fg, bg,
119121
separator if separator is not None else self.separator,
120122
separator_fg if separator_fg is not None else bg))
@@ -129,16 +131,12 @@ def draw(self):
129131

130132
def draw_segment(self, idx):
131133
segment = self.segments[idx]
132-
if self.args.shell == "bash":
133-
sanitized = re.sub(r"([`$])", r"\\\1", segment[0])
134-
else:
135-
sanitized = segment[0]
136134
next_segment = self.segments[idx + 1] if idx < len(self.segments)-1 else None
137135

138136
return ''.join((
139137
self.fgcolor(segment[1]),
140138
self.bgcolor(segment[2]),
141-
sanitized,
139+
segment[0],
142140
self.bgcolor(next_segment[2]) if next_segment else self.reset,
143141
self.fgcolor(segment[4]),
144142
segment[3]))
@@ -148,6 +146,7 @@ def find_config():
148146
for location in [
149147
"powerline-shell.json",
150148
"~/.powerline-shell.json",
149+
os.path.join(os.environ.get("XDG_CONFIG_HOME", "~/.config"), "powerline-shell", "config.json"),
151150
]:
152151
full = os.path.expanduser(location)
153152
if os.path.exists(full):
@@ -203,7 +202,12 @@ def main():
203202
config_path = find_config()
204203
if config_path:
205204
with open(config_path) as f:
206-
config = json.loads(f.read())
205+
try:
206+
config = json.loads(f.read())
207+
except Exception as e:
208+
warn("Config file ({0}) could not be decoded! Error: {1}"
209+
.format(config_path, e))
210+
config = DEFAULT_CONFIG
207211
else:
208212
config = DEFAULT_CONFIG
209213

powerline_shell/color_compliment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
def getOppositeColor(r,g,b):
13+
r, g, b = [x/255.0 for x in [r, g, b]] # convert to float before getting hls value
1314
hls = rgb_to_hls(r,g,b)
1415
opp = list(hls[:])
1516
opp[0] = (opp[0]+0.2)%1 # shift hue (a.k.a. color)

powerline_shell/segments/bzr.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
import os
21
import subprocess
3-
from ..utils import RepoStats, ThreadedSegment
4-
5-
6-
def get_PATH():
7-
"""Normally gets the PATH from the OS. This function exists to enable
8-
easily mocking the PATH in tests.
9-
"""
10-
return os.getenv("PATH")
11-
12-
13-
def bzr_subprocess_env():
14-
return {"PATH": get_PATH()}
2+
from ..utils import RepoStats, ThreadedSegment, get_subprocess_env
153

164

175
def _get_bzr_branch():
186
p = subprocess.Popen(['bzr', 'nick'],
197
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
20-
env=bzr_subprocess_env())
8+
env=get_subprocess_env())
219
branch = p.communicate()[0].decode("utf-8").rstrip('\n')
2210
return branch
2311

@@ -47,7 +35,7 @@ def build_stats():
4735
try:
4836
p = subprocess.Popen(['bzr', 'status'],
4937
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
50-
env=bzr_subprocess_env())
38+
env=get_subprocess_env())
5139
except OSError:
5240
# Popen will throw an OSError if bzr is not found
5341
return (None, None)

powerline_shell/segments/cwd.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ def add_cwd_segment(powerline):
5858
cwd = cwd.decode("utf-8")
5959
cwd = replace_home_dir(cwd)
6060

61-
if powerline.segment_conf("cwd", "mode") == 'plain':
62-
powerline.append(' %s ' % (cwd,), powerline.theme.CWD_FG, powerline.theme.PATH_BG)
63-
return
64-
6561
names = split_path_into_names(cwd)
6662

6763
full_cwd = powerline.segment_conf("cwd", "full_cwd", False)
@@ -84,6 +80,12 @@ def add_cwd_segment(powerline):
8480
# displayed, so chop everything else off
8581
names = names[-1:]
8682

83+
elif powerline.segment_conf("cwd", "mode") == "plain":
84+
joined = os.path.sep.join(names)
85+
powerline.append(" %s " % (joined,), powerline.theme.CWD_FG,
86+
powerline.theme.PATH_BG)
87+
return
88+
8789
for i, name in enumerate(names):
8890
is_last_dir = (i == len(names) - 1)
8991
fg, bg = get_fg_bg(powerline, name, is_last_dir)

powerline_shell/segments/fossil.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
import os
22
import subprocess
3-
from ..utils import RepoStats, ThreadedSegment
4-
5-
6-
def get_PATH():
7-
"""Normally gets the PATH from the OS. This function exists to enable
8-
easily mocking the PATH in tests.
9-
"""
10-
return os.getenv("PATH")
11-
12-
13-
def fossil_subprocess_env():
14-
return {"PATH": get_PATH()}
3+
from ..utils import RepoStats, ThreadedSegment, get_subprocess_env
154

165

176
def _get_fossil_branch():
@@ -49,7 +38,7 @@ def build_stats():
4938
try:
5039
subprocess.Popen(['fossil'], stdout=subprocess.PIPE,
5140
stderr=subprocess.PIPE,
52-
env=fossil_subprocess_env()).communicate()
41+
env=get_subprocess_env()).communicate()
5342
except OSError:
5443
# Popen will throw an OSError if fossil is not found
5544
return (None, None)

powerline_shell/segments/git.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
import re
22
import subprocess
3-
import os
4-
from ..utils import RepoStats, ThreadedSegment
5-
6-
7-
def get_PATH():
8-
"""Normally gets the PATH from the OS. This function exists to enable
9-
easily mocking the PATH in tests.
10-
"""
11-
return os.getenv("PATH")
12-
13-
14-
def git_subprocess_env():
15-
return {
16-
# LANG is specified to ensure git always uses a language we are expecting.
17-
# Otherwise we may be unable to parse the output.
18-
"LANG": "C",
19-
20-
# https://github.com/milkbikis/powerline-shell/pull/126
21-
"HOME": os.getenv("HOME"),
22-
23-
# https://github.com/milkbikis/powerline-shell/pull/153
24-
"PATH": get_PATH(),
25-
}
3+
from ..utils import RepoStats, ThreadedSegment, get_git_subprocess_env
264

275

286
def parse_git_branch_info(status):
@@ -33,7 +11,7 @@ def parse_git_branch_info(status):
3311
def _get_git_detached_branch():
3412
p = subprocess.Popen(['git', 'describe', '--tags', '--always'],
3513
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
36-
env=git_subprocess_env())
14+
env=get_git_subprocess_env())
3715
detached_ref = p.communicate()[0].decode("utf-8").rstrip('\n')
3816
if p.returncode == 0:
3917
branch = u'{} {}'.format(RepoStats.symbols['detached'], detached_ref)
@@ -63,7 +41,7 @@ def build_stats():
6341
try:
6442
p = subprocess.Popen(['git', 'status', '--porcelain', '-b'],
6543
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
66-
env=git_subprocess_env())
44+
env=get_git_subprocess_env())
6745
except OSError:
6846
# Popen will throw an OSError if git is not found
6947
return (None, None)

powerline_shell/segments/git_stash.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import subprocess
2+
from ..utils import RepoStats, ThreadedSegment, get_git_subprocess_env
3+
4+
5+
def get_stash_count():
6+
try:
7+
p = subprocess.Popen(['git', 'stash', 'list'],
8+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
9+
env=get_git_subprocess_env())
10+
except OSError:
11+
return 0
12+
13+
pdata = p.communicate()
14+
if p.returncode != 0:
15+
return 0
16+
17+
return pdata[0].count(b'\n')
18+
19+
20+
class Segment(ThreadedSegment):
21+
def run(self):
22+
self.stash_count = get_stash_count()
23+
24+
def add_to_powerline(self):
25+
self.join()
26+
if not self.stash_count:
27+
return
28+
29+
bg = self.powerline.theme.GIT_STASH_BG
30+
fg = self.powerline.theme.GIT_STASH_FG
31+
32+
sc = self.stash_count if self.stash_count > 1 else ''
33+
stash_str = u' {}{} '.format(sc, RepoStats.symbols['stash'])
34+
self.powerline.append(stash_str, fg, bg)

powerline_shell/segments/hg.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
import os
21
import subprocess
3-
from ..utils import RepoStats, ThreadedSegment
4-
5-
6-
def get_PATH():
7-
"""Normally gets the PATH from the OS. This function exists to enable
8-
easily mocking the PATH in tests.
9-
"""
10-
return os.getenv("PATH")
11-
12-
13-
def hg_subprocess_env():
14-
return {"PATH": get_PATH()}
2+
from ..utils import RepoStats, ThreadedSegment, get_subprocess_env
153

164

175
def _get_hg_branch():
186
p = subprocess.Popen(["hg", "branch"],
197
stdout=subprocess.PIPE,
208
stderr=subprocess.PIPE,
21-
env=hg_subprocess_env())
9+
env=get_subprocess_env())
2210
branch = p.communicate()[0].decode("utf-8").rstrip('\n')
2311
return branch
2412

@@ -46,7 +34,7 @@ def build_stats():
4634
p = subprocess.Popen(["hg", "status"],
4735
stdout=subprocess.PIPE,
4836
stderr=subprocess.PIPE,
49-
env=hg_subprocess_env())
37+
env=get_subprocess_env())
5038
except OSError:
5139
# Will be thrown if hg cannot be found
5240
return None, None

0 commit comments

Comments
 (0)