-
-
Save kaihendry/bc4be133863313bc468677c97c0c0937 to your computer and use it in GitHub Desktop.
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
#!/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