diff --git a/README.rst b/README.rst index 680adc0..858b25c 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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 @@ -35,34 +35,45 @@ 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 -------- @@ -70,6 +81,7 @@ 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 ------------ diff --git a/docs/color-changing.png b/docs/color-changing.png new file mode 100644 index 0000000..4520671 Binary files /dev/null and b/docs/color-changing.png differ diff --git a/docs/ordinary.png b/docs/ordinary.png index 86a0627..678edb6 100644 Binary files a/docs/ordinary.png and b/docs/ordinary.png differ diff --git a/docs/yolog-powered.png b/docs/yolog-powered.png index a6bca3f..8a18c92 100644 Binary files a/docs/yolog-powered.png and b/docs/yolog-powered.png differ diff --git a/setup.py b/setup.py index 56b5364..6c08a5e 100644 --- a/setup.py +++ b/setup.py @@ -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='karandesai281196@gmail.com', - 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'] diff --git a/yolog/__init__.py b/yolog/__init__.py index c20d6cf..3dadfef 100644 --- a/yolog/__init__.py +++ b/yolog/__init__.py @@ -1,4 +1,7 @@ -__author__ = "Karan Desai" -__email__ = "karandesai281196@gmail.com" -__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__ = 'karandesai281196@gmail.com' +__license__ = 'MIT' diff --git a/yolog/config_handler.py b/yolog/config_handler.py index 8e8cfea..e51dc2b 100644 --- a/yolog/config_handler.py +++ b/yolog/config_handler.py @@ -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() + )) diff --git a/yolog/main.py b/yolog/main.py index d3abcd4..f38ef91 100644 --- a/yolog/main.py +++ b/yolog/main.py @@ -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 [] - -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(' ')) diff --git a/yolog/yolog_generator.py b/yolog/yolog_generator.py index 031887f..860cfa4 100644 --- a/yolog/yolog_generator.py +++ b/yolog/yolog_generator.py @@ -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} [] + +{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() @@ -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 + )) + )