Skip to content

Commit

Permalink
Add --filter flag
Browse files Browse the repository at this point in the history
The normal approach to filtering would be to just use Unix pipes.
That strategy doesn't work well here, because the histogram max width is
determined by the line with the most commits. So if one file has been
changed 1000 times and all the rest are orders of magnitude smaller,
the bar chart will have a lot of unused space.
  • Loading branch information
jez committed Jan 11, 2018
1 parent 9c55277 commit 258cb79
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions git-heatmap
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
-f|--filter)
FILTER="$2"
shift
shift
;;
-h)
cat <<EOF
Heatmap of oft-edited files.
Expand All @@ -44,6 +49,8 @@ Options:
-b <branch>, --base <branch> Compare relative to <branch>. If on <branch>,
show heatmap for entire repo. [default: master]
-c <char>, --char <char> Use <char> to draw the bars. [default: █]
-f <cmd>, --filter <cmd> Filter output through <cmd> before creating the
the histogram.
-h Show this message.
EOF
exit
Expand All @@ -59,6 +66,7 @@ LIMIT=${LIMIT:-30}
REVIEW_BASE=${REVIEW_BASE:-master}
CHAR=${CHAR:-█}
WIDTH=${WIDTH:-60}
FILTER=${FILTER:-cat -}

files() {
# https://stackoverflow.com/questions/7577052/
Expand All @@ -76,6 +84,7 @@ color_name() {

filter() {
grep '.' | \
eval "$FILTER" | \
sort | \
uniq -c | \
sort -nr | \
Expand Down

0 comments on commit 258cb79

Please sign in to comment.