git-who 745 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python3
  2. '''
  3. git blame a file repeatedly, showing the blame at previous versions
  4. '''
  5. import re
  6. import subprocess
  7. import sys
  8. def main():
  9. commit = 'HEAD'
  10. while True:
  11. blame = subprocess.Popen(['git-blame', *sys.argv[1:], commit],
  12. stdout=subprocess.PIPE)
  13. try:
  14. blame = subprocess.Popen(['delta', '--color-only'],
  15. stdin=blame.stdout, stdout=subprocess.PIPE)
  16. except FileNotFoundError:
  17. pass
  18. fzf = subprocess.run(['fzf', '--no-sort', '--tiebreak=index', '--reverse', '--ansi'],
  19. stdin=blame.stdout, stdout=subprocess.PIPE, text=True)
  20. blame.wait()
  21. if fzf.returncode in (1, 130): # no match, esc
  22. return
  23. commit = re.search('[0-9a-f]{7,40}', fzf.stdout).group(0) + '^'
  24. if __name__ == '__main__':
  25. main()