Created
April 8, 2020 17:18
-
-
Save mcoffin/45538e8a80a69206234aa7cd478986d3 to your computer and use it in GitHub Desktop.
catdir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/zsh | |
set -e | |
function print_usage() { | |
echo 'Usage: catdir DIR...' | |
} | |
function catdir() { | |
local d="${1:-.}" | |
for f in $(find "$d" -type f); do | |
echo -e "\033[0;36m$f\033[0m:" | |
cat "$f" | |
echo | |
done | |
} | |
while getopts ":h" opt; do | |
case ${opt} in | |
h) | |
print_usage | |
exit 0 | |
;; | |
\?) | |
echo "Unknown argument: -$OPTARG" >2 | |
exit 1 | |
;; | |
:) | |
printf "Invalid argument: -%s requires an argument\n" "$OPTARG" >&2 | |
exit 1 | |
;; | |
esac | |
done | |
shift $((OPTIND -1)) | |
if [ $# -lt 1 ]; then | |
catdir | |
else | |
while [ $# -gt 0 ]; do | |
catdir "$1" | |
shift | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment