Skip to content

Commit 88487a7

Browse files
authored
Merge pull request #12 from bclarkx2/dev
Merge feature: stash indicator
2 parents 2349610 + 4b57535 commit 88487a7

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

pwd.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def repo_information(pwd):
6666

6767
for i in range(2, len(pwd_list)+1):
6868
current_dir = pwd_list[:i]
69+
70+
# Bail out if pwd is IN the VCS data dir
71+
if current_dir[-1] in vcs_subdirs:
72+
return [], [], ""
73+
6974
vcs_subdir = get_vcs_subdir(current_dir)
7075
if vcs_subdir:
7176
last_repo = current_dir
@@ -127,7 +132,11 @@ def git_branch_info(repo_path, vcs_subdir):
127132
if dirty:
128133
local += "*"
129134

130-
return local, remote, divergence
135+
stash_output = subprocess.check_output(["git", "stash", "list"])
136+
stash_lines = stash_output.decode(encoding="utf-8").splitlines()
137+
stashes = len(stash_lines)
138+
139+
return local, remote, divergence, stashes
131140

132141

133142
def virtual_env(pwd):
@@ -171,6 +180,8 @@ def format_name(fmt, name, color):
171180
else:
172181
return ""
173182

183+
def format_stashes(stashes):
184+
return "".join("." * stashes)
174185

175186
###############################################################################
176187
# Main #
@@ -187,7 +198,10 @@ def main():
187198
hostname = gethostname()
188199
username = os.getenv('USER')
189200
repo, repo_path, vcs_subdir = repo_information(pwd)
190-
branch, remote, div = branch_info(repo_path, vcs_subdir) if repo else ("", "", "")
201+
if repo:
202+
branch, remote, div, stashes = branch_info(repo_path, vcs_subdir)
203+
else:
204+
branch, remote, div, stashes = "", "", "", ""
191205
virtualenv = virtual_env(pwd)
192206

193207
# Format pieces for display
@@ -196,6 +210,7 @@ def main():
196210
repo = format_name("[{}]", repo, FCYN)
197211
branch = format_name("({})", branch, FMAG)
198212
remote = format_name("↑{{{}}}", remote, FBLE)
213+
stash = format_stashes(stashes)
199214

200215
# Combine into display
201216
prompt = ''.join([
@@ -209,6 +224,7 @@ def main():
209224
branch,
210225
div,
211226
virtualenv,
227+
stash,
212228
os.linesep,
213229
FYEL,
214230
CURSOR,

0 commit comments

Comments
 (0)