Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
Merge pull request #10 from karandesai-96/v0.3-cleanup
Browse files Browse the repository at this point in the history
Final cleanup and description updates before v0.3.0.
  • Loading branch information
Karan Desai authored Jul 14, 2016
2 parents 8f40117 + 7e6cdf8 commit c2561ce
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 101 deletions.
68 changes: 40 additions & 28 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Here is how default git logs look like:

.. image:: https://raw.githubusercontent.com/karandesai-96/yolog/master/docs/ordinary.png

Yolog wraps over standard git log and represents commit message history in a compact
manner. It provides a visualization of commit graph, and shows refs, tags and unmerged
branches altogether. A yolog powered git log looks like this:
Yolog wraps over standard git log and represents commit message history in a compact manner. It provides a
visualization of commit graph, and shows refs, tags and unmerged branches altogether. A yolog powered git log looks
like this:

.. image:: https://raw.githubusercontent.com/karandesai-96/yolog/master/docs/yolog-powered.png

Expand All @@ -22,10 +22,10 @@ Obtain stable release from PyPI
::
pip install yolog

To obtain the bleeding edge version, clone the repo and build it from source:
Alternatively, to obtain the bleeding edge version, clone the repo and build it from source:
::
git clone https://www.github.com/karandesai-96/yolog
cd yolog && python setup.py build
cd yolog && python setup.py install


Usage
Expand All @@ -35,41 +35,53 @@ Usage

* For brief instructions, execute ``yolog -h`` or ``yolog --help`` in terminal.

It also accepts arguments which are used to filter output.
These arguments are same as those accepted by standard git log.
* For changing color of any attribute, execute command of format ``yolog config attribute COLOR``.

- Alternatively, ``-c`` or ``--config`` work as well.
- ``attribute`` can be one of: ``author, date, description, hash, refs``
- ``COLOR`` can be one of: ``RED, GREEN, YELLOW, BLUE, CYAN, PURPLE, BLACK, WHITE``
- Arguments ``attribute`` and ``COLOR`` are case insensitive.

.. image:: https://raw.githubusercontent.com/karandesai-96/yolog/master/docs/color-changing.png

* It also accepts arguments which are used to filter output. These arguments are same as those accepted by standard
git log.

Here are the most common used ones:

+-----------------------------------+---------------------------------------------------------+
| Command Example | Description |
+===================================+=========================================================+
| ``yolog -n`` | Display recent ``n`` commits. |
+-----------------------------------+---------------------------------------------------------+
| ``yolog --skip=n`` | Skip recent ``n`` commits and display further. |
+-----------------------------------+---------------------------------------------------------+
| ``yolog --author=karan`` | Filter commits according to author. Part of name / whole|
| | will be accepted. |
+-----------------------------------+---------------------------------------------------------+
| ``yolog --before=dd-mmm-yyyy`` | Display commits before this date. |
+-----------------------------------+ |
| ``yolog --until=dd/mmm/yyyy`` | |
+-----------------------------------+---------------------------------------------------------+
| ``yolog --after=dd/mmm/yyyy`` | Display commits after this date. |
+-----------------------------------+ |
| ``yolog --since=dd-mmm-yyyy`` | |
+-----------------------------------+---------------------------------------------------------+
| ``yolog --grep="foo\ bar"`` | Display commits with "foo bar" in their description. |
+-----------------------------------+---------------------------------------------------------+
+-------------------------------------+---------------------------------------------------------+
| Command Example | Description |
+=====================================+=========================================================+
| ``yolog -n N`` | Display recent ``N`` commits. |
+-------------------------------------+---------------------------------------------------------+
| ``yolog --skip N`` | Skip recent ``N`` commits and display further. |
+-------------------------------------+---------------------------------------------------------+
| ``yolog --author "john\ doe"`` | Filter commits according to author. |
| | Part of name / whole will be accepted. |
+-------------------------------------+---------------------------------------------------------+
| ``yolog --before dd-mmm-yyyy`` | Display commits before this date. |
| | |
| ``yolog --until dd/mmm/yyyy`` | Hyphen (-) or slash (/) can be used interchangeably. |
+-------------------------------------+---------------------------------------------------------+
| ``yolog --after dd/mmm/yyyy`` | Display commits after this date. |
| | |
| ``yolog --since dd-mmm-yyyy`` | Hyphen (-) or slash (/) can be used interchangeably. |
+-------------------------------------+---------------------------------------------------------+
| ``yolog --grep "foo\ bar"`` | Display commits with "foo bar" in their description. |
+-------------------------------------+---------------------------------------------------------+

* Any of these can be combined together and used.
* ``=`` can be optionally used in args as: ``yolog --skip=10``
* Regular expressions are also accepted in ``grep`` and ``author``.
* Use escape character if using whitespace: ``yolog --grep="fixes\ bug"``
* Use inverted commas and escape character if using whitespace: ``yolog --grep "fixes\ bug"``

Features
--------

- Tabulated commit history with shortened hashes, author, date and commit message (refs included if present).
- Colored fields for better readability, with visualization of commit graph.
- Vertical as well as horizontol pagination for longer commit history / smaller terminal window.
- Flexibility to change color of any part of log by a single command.

Contributing
------------
Expand Down
Binary file added docs/color-changing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/ordinary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/yolog-powered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

setup(
name='yolog',
version='0.2.2',
description='Beautify your git logs!',
url='http://github.com/karandesai-96/yolog',
author='Karan Desai',
author_email='[email protected]',
license='MIT',
version=__import__('yolog').__version__,
description=__import__('yolog').__description__,
url=__import__('yolog').__url__,
author=__import__('yolog').__author__,
author_email=__import__('yolog').__email__,
license=__import__('yolog').__license__,
packages=['yolog'],
entry_points={
'console_scripts': ['yolog = yolog.main:main']
Expand Down
11 changes: 7 additions & 4 deletions yolog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
__author__ = "Karan Desai"
__email__ = "[email protected]"
__version__ = "0.2.2"
__license__ = "MIT"
__name__ = 'yolog'
__version__ = '0.3'
__description__ = 'Beautify your Git Logs !'
__url__ = 'https://www.github.com/karandesai-96/yolog'
__author__ = 'Karan Desai'
__email__ = '[email protected]'
__license__ = 'MIT'
28 changes: 18 additions & 10 deletions yolog/config_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@
from configparser import SafeConfigParser



class ConfigHandler(object):
def __init__(self, path):
self.path = os.path.expandvars(os.path.expanduser(path))
self.config = SafeConfigParser()
self.config.read(self.path)

def set_color(self, attribute, color):
if attribute not in {"author", "date", "description", "hash", "refs"}:
self.config_parser = SafeConfigParser()
self.config_parser.read(self.path)

self.attributes = {'author', 'date', 'description', 'hash', 'refs'}
self.colors = {'WHITE', 'BLACK', 'RED', 'YELLOW', 'GREEN', 'BLUE',
'CYAN', 'PURPLE'}

def update_color(self, attribute, color):
if attribute.lower() not in self.attributes:
print("{0}: Invalid attribute !".format(attribute))
elif color.upper() not in {"WHITE", "BLACK", "RED", "GREEN",
"CYAN", "BLUE", "PURPLE", "YELLOW"}:
print("Choose one of {0}.".format(self.attributes))
elif color.upper() not in self.colors:
print("{0}: Invalid color !".format(color))
print("Choose one of {0}.".format(self.colors))
else:
self.config.set("color", attribute, color.upper())
self.config_parser.set("color", attribute.lower(), color.upper())

with open(self.path, 'w') as f:
self.config.write(f)
print("Changed Successfully !")
self.config_parser.write(f)
print("Updated {0} color of {1} attribute successfully !".format(
color.upper(), attribute.lower()
))
59 changes: 15 additions & 44 deletions yolog/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,24 @@
from yolog.yolog_generator import YologGenerator
from yolog.config_handler import ConfigHandler

help_description = ("""
Yolog - Beautify your Git logs !
--------------------------------
Usage: yolog [<additional optional commands>]
1. yolog -n
- Display recent n commits.
2. yolog --skip=n
- Skip recent n commits and display further.
3. yolog --author=john
- Filter commits according to author.
Part of name / whole will be accepted.
4. yolog --before=dd-mmm-yyyy
yolog --until=dd/mmm/yyyy
- Display commits before this date.
5. yolog --after=dd/mmm/yyyy
yolog --since=dd-mmm-yyyy
- Display commits after this date.
6. yolog --grep="foo\ bar"
- Display commits with "foo bar" in their description.
7. yolog --help
yolog -h
- Display this instruction.
* Any of these can be combined together and used.
* Regular expressions are also accepted in grep and author.
* Use escape character if using whitespace: yolog --grep="fixes\ bug"
""")


def main():
git_arguments = sys.argv[1:]
config_filepath = '~/.yolog/config.ini'

if git_arguments:
if sys.argv[1] in {"-h", "--help", "help"}:
print(help_description)
elif sys.argv[1] in {"-c", "--config", "config"}:
config_handler = ConfigHandler("~/.yolog/config.ini")
config_handler.set_color(sys.argv[2], sys.argv[3])
if sys.argv[1] in {'-h', '--help', 'help'}:
yolog_gen = YologGenerator(config_filepath)
os.system(yolog_gen.print_help())

elif sys.argv[1] in {'-c', '--config', 'config'}:
config_handler = ConfigHandler(config_filepath)
config_handler.update_color(sys.argv[2], sys.argv[3])

else:
yolog_gen = YologGenerator("~/.yolog/config.ini")
os.system(yolog_gen.git_command(" ".join(git_arguments)))
yolog_gen = YologGenerator(config_filepath)
os.system(yolog_gen.git_command(' '.join(git_arguments)))

else:
yolog_gen = YologGenerator("~/.yolog/config.ini")
os.system(yolog_gen.git_command(" "))
yolog_gen = YologGenerator(config_filepath)
os.system(yolog_gen.git_command(' '))
81 changes: 72 additions & 9 deletions yolog/yolog_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,70 @@
from configparser import SafeConfigParser



RESET = "$(tput sgr0)"
RESET = "$(tput sgr0)"
BACKSPACE = "%x08"

help_description = ("""
{yellow}Yolog - Beautify your Git logs !
{white}================================
{cyan}Author: {author}
{cyan}Version: {version}
{cyan}Usage: yolog [-h|--help] [-c|--config attribute COLOR]
{cyan} [<additional commands>]
{yellow}HELP MESSAGE
{white}------------
{green} -h or --help
{white} Display this help description.
{yellow}COLOR CHANGING
{white}--------------
{green} -c attribute COLOR or --config attribute COLOR
{white} Change color of 'attribute' to 'COLOR'.
{white} attribute: author, date, description, hash, refs
{white} COLOR: RED, GREEN, YELLOW, BLUE, CYAN, PURPLE, BLACK, WHITE
{yellow}ADDITIONAL COMMANDS
{white}-------------------
{green} -N or -n N
{white} Display recent n commits.
{green} --skip N
{white} Skip recent N commits and display further.
{green} --author "john\ doe"
{white} Filter commits according to name of author.
{white} Part of name / whole will be accepted.
{green} --before DD-MMM-YYYY or --until DD/MMM/YYYY
{white} Display commits before this date.
{white} Hyphen(-) and forward slash(/) can be used interchangeably.
{green} --after DD/MMM/YYYY or --since DD-MMM-YYYY
{white} Display commits after this date.
{white} Hyphen(-) and forward slash(/) can be used interchangeably.
{green} --grep "foo\ bar"
{white} Display commits with "foo bar" in their description.
{cyan} * Any of these can be combined together and used.
{cyan} * Regular expressions are also accepted in grep and author.
{cyan} * Use escape character if using whitespace: yolog --grep="fixes\ bug"
{reset}""")


class YologGenerator(object):
BLACK = "$(tput bold)$(tput setaf 0)"
RED = "$(tput bold)$(tput setaf 1)"
GREEN = "$(tput bold)$(tput setaf 2)"
BLACK = "$(tput bold)$(tput setaf 0)"
RED = "$(tput bold)$(tput setaf 1)"
GREEN = "$(tput bold)$(tput setaf 2)"
YELLOW = "$(tput bold)$(tput setaf 3)"
BLUE = "$(tput bold)$(tput setaf 4)"
BLUE = "$(tput bold)$(tput setaf 4)"
PURPLE = "$(tput bold)$(tput setaf 5)"
CYAN = "$(tput bold)$(tput setaf 6)"
WHITE = "$(tput setaf 7)"
CYAN = "$(tput bold)$(tput setaf 6)"
WHITE = "$(tput setaf 7)"

def __init__(self, path):
self.config = SafeConfigParser()
Expand Down Expand Up @@ -50,4 +100,17 @@ def git_command(self, git_arguments):
"column -t -s \";;\" | less -FXRS".format(
self._format, git_arguments
)
)
)

def print_help(self):
return (
"echo \"{0}\" | less -RS".format(help_description.format(
author=__import__('yolog').__author__,
version=__import__('yolog').__version__,
yellow=self.YELLOW,
green=self.GREEN,
cyan=self.CYAN,
white=self.WHITE,
reset=RESET
))
)

0 comments on commit c2561ce

Please sign in to comment.