git历史查看工具
- 2019 年 11 月 22 日
- 笔记
哈哈。终于把之前公司那个玩意重写了。
效果

配置
vim ~/.bashrc alias ghis="python2 /workspace/git_history/git_history.py"
注意,代码中可以配置显示详细信息:
class CommitInfo(): def __init__(self): ... self.is_simple = True
源码
# coding:utf-8 import os import subprocess import sys filename = sys.argv[1] find_text = sys.argv[2] try: is_blame = sys.argv[3] except: is_blame = False def cmd(cmdstr): return subprocess.check_output(cmdstr, shell=True) dir_path = os.getcwd() filename = dir_path + "/" + filename # 打印查询结果前后的行 near_lines = 5 class Queue(object): def __init__(self, max_lines): self.q = [] self.max_lines = max_lines self.pos = 0 self.key = "" # key会被显色加粗 def append(self, val): if len(self.q) > self.max_lines: self.q.pop(0) self.q.append(val) self.pos += 1 def print_me(self): for item in self.q: if self.key: item = item.replace(self.key, "