Skip to content

Instantly share code, notes, and snippets.

@kaihendry
Created July 12, 2020 13:27
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/bc4be133863313bc468677c97c0c0937 to your computer and use it in GitHub Desktop.
Save kaihendry/bc4be133863313bc468677c97c0c0937 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
cache=~/.cache/sloc
count () {
local in
read -r in
set -- "$in"
fullpath=$(readlink -f "${1:-.}")
echo Full path: "$fullpath"
test -d "$1" && cd "$1"
count=${cache}${fullpath}/count
if ! test -f "$count"
then
cachedir=${cache}${fullpath}
echo mkdir for cachedir "$cachedir" >&2
mkdir -v -p "$cachedir" || true
for i in *
do
echo Counting "$i" >&2
dirsep=$(test -d "$i" && echo /)
#echo ${i}${dirsep} $(find $i -type f -exec cat {} + | wc -l)
echo "${i}""${dirsep}" $(find "$i" -type f -exec cat {} + | wc -l)
done | sort -k2 -n -r > "$count"
else
echo Using pre-existing cache "$count" >&2
fi
dmenu -l 10 < "$count" | count
}
echo "${1:-.}" | count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment