#! /bin/zsh

prog=${0##*/}
case $# in 0) print >&2 "usage: $prog COMMAND"; exit 127 ;; esac

run () {
  firstp=t
  for i in **/description(.); do
    r=${i%/*}
    if ! [[ -f $r/HEAD && -d $r/objects && -d $r/refs ]]; then continue; fi
    case $firstp in t) firstp=nil ;; nil) print ;; esac
    print -P "%B%F{cyan};; $r$post%f%b"
    (export GIT_DIR=$r; eval "$*")
  done
}

if [[ -t 1 ]]; then run "$@" |& ${PAGER-less}
else run "$@"
fi
