#!/usr/bin/env sh
#
# insubs - runs a given command in each immediate subdirectory
#
# usage: insubs {{command}}
#
# ---
# based on: https://stackoverflow.com/a/41575863/1973105

set -eu

cmd="$*"
# shellcheck disable=SC2016,SC2312
find . -maxdepth 1 -mindepth 1 -type d -print0 \
  | xargs -0 -I{} sh -c -- 'cd "{}" && echo "\033[36;1;4m{}\033[0m\n" && echo "$('"${cmd}"')" && printf '\''%b\n'\'''

# export cmd=$@
# find . -type d -maxdepth 1 -mindepth 1 -print0 \
#   | xargs -0 -I{} zsh -c 'cd "{}" && echo "\033[36;1;4m{}\033[0m\n" && echo "$('$cmd')" && echo -e'
