From 3c52d76997a328af0afd39f0c369ed2e216e0775 Mon Sep 17 00:00:00 2001 From: Jake Zimmerman Date: Wed, 10 Jan 2018 13:29:52 -0800 Subject: [PATCH] Correctly handle when ARGV is empty 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. --- git-heatmap | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/git-heatmap b/git-heatmap index bd941b2..6fb6794 100755 --- a/git-heatmap +++ b/git-heatmap @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash # Build a commit frequency histogram @@ -7,7 +7,7 @@ cnone="$(echo -ne '\033[0m')" set -euo pipefail -argv=() +ARGV=() while [[ $# -gt 0 ]]; do key="$1" case $key in @@ -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() {