Skip to content

Instantly share code, notes, and snippets.

@decal
Created December 31, 2018 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save decal/2da84aa82384cd01440a9a1b0a0c7f2d to your computer and use it in GitHub Desktop.
Save decal/2da84aa82384cd01440a9a1b0a0c7f2d to your computer and use it in GitHub Desktop.
Describe GitHub repositories residing under given local file system directory
#!/usr/bin/env bash
#
# github-repo-desc (GitHub Repository Describer)
#
# Describe GitHub repositories residing under given local file system directory
#
# Written By: Derek Callaway [decal (AT) sdf {D0T} org]
# Last Updated: Mon Dec 31 10:42:14 PST 2018
# Tested On: macOS High Sierra and CentOS GNU/Linux
#
if [ ! "$1" ]
then echo
echo "usage: [AVAR=1] $0 PATH"
echo
echo ' AVAR optional environment variable to change output formatting:'
echo
echo ' REPODESC_MARKDOWN output as markdown'
echo ' REPODESC_MARKUP output as HTML'
echo
echo ' PATH path name of directory containing GitHub repositories'
echo
echo "ex. REPODESC_MARKDOWN=1 $0 ~/github"
echo
exit 1
fi
[[ $REPODESC_MARKUPDN ]] || [[ $REPODESC_MARKDNUP ]] && declare -i REPODESC_MARKDOWN=1 REPODESC_MARKUP=1
readonly rpfile="/tmp/.repos.$$"
echo
for adir in $*; do
(for arepo in $(find $adir -type f -name 'config' -print | grep '/.git/config'); do
declare ghpath=$(grep 'url = ' $arepo | rev | cut -d '/' -f1-2 | rev)
echo $ghpath
done) | sort -u > "$rpfile"
for xrepo in $(cat "$rpfile")
do declare ghdesc=$(curl -kv "https://api.github.com/repos/${xrepo}" 2>/dev/null | grep '"description"' | head -n 1 | awk -F: '{print$2}' | awk -F, '{print$1}' | tr -d '"' | sed 's!^[[:space:]]*!!')
if [ $REPODESC_MARKDOWN ]
then echo -n "[${xrepo}](https://github.com/${xrepo}"
[ "$ghdesc" ] && echo -n " \"${ghdesc}\""
echo ')'
echo
continue
fi
if [ $REPODESC_MARKUP ]
then echo -n "<a href=\"https://github.com/${xrepo}\""
[ "$ghdesc" ] && echo -n " alt=\"${ghdesc}\""
echo ">${xrepo}</a><br />"
echo
continue
fi
echo "$xrepo $ghdesc"
echo
done
done
rm -f -- "$rpfile"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment