Skip to content

Commit

Permalink
Correctly handle when ARGV is empty
Browse files Browse the repository at this point in the history
If it's empty, in older bash versions bash will say "undefined variable"
when converting the array to a list of arguments. The `foo+...` part
says what to do in the edge case.
  • Loading branch information
jez committed Jan 10, 2018
1 parent 6faedb2 commit 3c52d76
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions git-heatmap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash

# Build a commit frequency histogram

Expand All @@ -7,7 +7,7 @@ cnone="$(echo -ne '\033[0m')"

set -euo pipefail

argv=()
ARGV=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
Expand Down Expand Up @@ -49,19 +49,21 @@ EOF
exit
;;
*)
argv+=("$1")
ARGV+=("$1")
shift
;;
esac
done

LIMIT=${LIMIT:-30}
WIDTH=${WIDTH:-60}
CHAR=${CHAR:-█}
REVIEW_BASE=${REVIEW_BASE:-master}
CHAR=${CHAR:-█}
WIDTH=${WIDTH:-60}

files() {
git log --name-status --pretty=format: -- "${argv[@]}" | cut -f 2-
# https://stackoverflow.com/questions/7577052/
git log --name-status --pretty=format: -- "${ARGV[@]+"${ARGV[@]}"}" | \
cut -f 2-
}

color_name() {
Expand Down

0 comments on commit 3c52d76

Please sign in to comment.