Skip to content

Commit

Permalink
add git active branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
edouard-lopez committed Mar 9, 2019
1 parent 3504d1a commit 08252c3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ keyring = "*"
[packages]
pytest = "*"
colorful = "*"
pure-prompt = {path = "."}
gitpython = "*"

[requires]
python_version = "3.6"
34 changes: 29 additions & 5 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions pure/prompt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse
import os

import git

from pure import colors

SUCCESS = 0
Expand All @@ -22,12 +24,20 @@ def virtual_env():
return ''


def git_active_branch(directory):
try:
repo = git.Repo(directory)
return colors.mute(str(repo.active_branch))
finally:
pass


def layout():
return "\n%s\n%s%s "
return "\n%s %s\n%s%s "


def prompt(args):
print(layout() % (current_working_path(), virtual_env(), prompt_symbol(args.last_command_status)))
print(layout() % (current_working_path(), git_active_branch(os.getcwd()), virtual_env(), prompt_symbol(args.last_command_status)))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pure",
version="1.2.5",
version="1.3.0",
author="Édouard Lopez",
author_email="contact@edouard-lopez.com",
description="Pretty, minimal and fast prompt for various shells",
Expand Down
17 changes: 16 additions & 1 deletion tests/prompt_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
from pathlib import Path
import tempfile

import git
from pure import prompt, colors

SUCCESS = 0
Expand Down Expand Up @@ -52,4 +54,17 @@ def test_displays_virtual_env_when_activated():
assert str(prompt.virtual_env()) == str(colors.mute('env '))

def test_prompt_layout():
assert prompt.layout() == '\n%s\n%s%s '
assert prompt.layout() == '\n%s %s\n%s%s '

def test_contains_git_branch_name():
with tempfile.TemporaryDirectory() as tmp_repo:
empyt_repo = git.Repo.init(tmp_repo)

assert 'master' in str(prompt.git_active_branch(tmp_repo))

def test_git_branch_name_color_is_mute():
with tempfile.TemporaryDirectory() as tmp_repo:
empyt_repo = git.Repo.init(tmp_repo)

assert str(prompt.git_active_branch(tmp_repo)) == str(colors.mute('master'))

0 comments on commit 08252c3

Please sign in to comment.