Hacker News new | ask | show | jobs
by patrck 1481 days ago
Yeah, it seems odd that a golang solution was used instead of just shell.

  paths() {
    dir=`dirname $1`
    while test "$dir" != '/' && test "$dir" != '.' ; do
      echo $dir
      dir=`dirname $dir`
    done
  }

  find $dir -type f -not -path '*/.git/*' | while read file; do
    cnt=`wc -l < $file`
    for d in `paths $file`; do
      printf "%s\t%s\n" $cnt "$d"
    done
  done | awk '{
    hierarchy[ $2 ] += $1;
  }
  END {
    for (dir in hierarchy) {
      printf("%8d %s\n", hierarchy[dir], dir)
    }
  }' | sort -rn | head | sort -k 2