Skip to content

Instantly share code, notes, and snippets.

@kaihendry
Created July 20, 2020 05:59
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 kaihendry/bc8835eddafdb8f92df0b4f019184e65 to your computer and use it in GitHub Desktop.
Save kaihendry/bc8835eddafdb8f92df0b4f019184e65 to your computer and use it in GitHub Desktop.
#!/bin/bash
cache=~/.cache/sloc2
count() {
echo Arg "$@" >&2
if ! test -d "$1"
then
echo $1 not a dir >&2
return
fi
cd $1
fullpath=$(readlink -f .)
count=${cache}${fullpath}/count
if ! test -f "$count"
then
cachedir=${cache}${fullpath}
mkdir -v -p "$cachedir"
for srcdir in *
do
echo -n "$srcdir " >&2
echo $srcdir$(test -d $srcdir && echo "/") $(find "$srcdir" -type f -exec cat {} + | wc -l)
done | sort -k2 -n -r > "$count"
else
echo Using pre-existing cache "$count" >&2
fi
nextdir=$(umenu < "$count")
count $nextdir
}
count "${1:-.}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment