diff --git a/README.md b/README.md new file mode 100644 index 0000000..9b4ce38 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# git-heatmap + +> Display a heatmap for oft-edited files + +![screenshot of git heatmap](screenshot.png) + +## Install + +### Dependencies + +You must have the `bars` command on your system first: + +``` +npm install -g https://github.com/jez/bars.git +``` + +### Installation + +Download `git-heatmap` and put it on your path. + +```bash +# Homebrew: +brew install jez/formulae/git-heatmap +``` + +## Usage + +``` +❯ git heatmap -h +Heatmap of oft-edited files. + +Usage: + git heatmap [options] [...] + +Options: + -n Limit to top files. [default: 30] + --width Limit histogram to chars. + -b , --base Compare relative to . If on , + show heatmap for entire repo. [default: master] + -h Show this message. +``` + +## License + +[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://jez.io/MIT-LICENSE.txt) diff --git a/git-heatmap b/git-heatmap new file mode 100755 index 0000000..da1a295 --- /dev/null +++ b/git-heatmap @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +# Build a commit frequency histogram + +ccyan="$(echo -ne '\033[0;36m')" +cnone="$(echo -ne '\033[0m')" + +argv=() +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + -n) + LIMIT="$2" + shift + shift + ;; + -b|--base) + REVIEW_BASE="$2" + shift + shift + ;; + -h) + cat <...] + +Options: + -n Limit to top files. [default: 30] + -b , --base Compare relative to . If on , + show heatmap for entire repo. [default: master] + -h Show this message. +EOF + exit + ;; + *) + argv+=("$1") + shift + ;; + esac +done + +LIMIT=${LIMIT:-30} +REVIEW_BASE=${REVIEW_BASE:-master} + +files() { + git log --name-status --pretty=format: -- "${argv[@]}" | cut -f 2- +} + +color_name() { + # \(.*\/\)\([^/ ]*\) + sed -e "s/\(..*\/\)*\(.[^|]*\) |/\1$ccyan\2$cnone |/" +} + +filter() { + sort | \ + uniq -c | \ + sort -nr | \ + tail -n +2 | \ + head -n "$LIMIT" +} + +if [[ "$(git branch | grep '\*')" =~ $REVIEW_BASE ]]; then + # If on master, show heatmap for whole repo + files | filter | bars --bar █ | color_name +else + MERGE_BASE="$(git merge-base HEAD "$REVIEW_BASE")" + files | \ + # If on separate branch, show heatmap for files changed since master + grep -xF -f <(git diff --name-only "$MERGE_BASE") | \ + filter | \ + bars --bar █ | \ + color_name +fi + diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..dfcd236 Binary files /dev/null and b/screenshot.png differ