Created
December 10, 2014 03:45
-
-
Save jhaynie/8375cff7d56eb751a0e9 to your computer and use it in GitHub Desktop.
find -E . -type f -not -regex "^\./\.git/.*" | awk 'BEGIN {FS="."} {tally[$NF]+=1} END {for (key in tally) {printf "%d: %s\n", tally[key], key}}' | sort -n -k 1,1 | tail -r
This file contains hidden or 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
// simple and quick port of | |
// | |
// find -E . -type f -not -regex "^\./\.git/.*" | awk 'BEGIN {FS="."} {tally[$NF]+=1} END {for (key in tally) {printf "%d: %s\n", tally[key], key}}' | sort -n -k 1,1 | tail -r | |
// | |
var wrench = require('wrench'), | |
fs = require('fs'), | |
path = require('path'), | |
_ = require('lodash'); | |
// process either current working directory or pass in as first arg | |
var dir = process.argv[2] || process.cwd(); | |
// read directory listing | |
var files = wrench.readdirSyncRecursive(dir); | |
// create tally hash | |
var tally = {}; | |
// walk through each file in array | |
files.forEach(function(fn){ | |
// if it's a file and it doesn't match regexp | |
if (fs.statSync(path.join(dir,fn)).isFile() && !/^\.\/\.git\/.*/.test(fn)) { | |
// extract file extension or just filename if no extension | |
var key = path.extname(fn).substring(1) || fn; | |
// record tally | |
if (key in tally) { | |
tally[key]++; | |
} | |
else { | |
tally[key] = 1; | |
} | |
} | |
}); | |
console.log( | |
// turn hash (key/value) into array of key/value then sort it inversely | |
_.pairs(tally).sort(function(a,b){ | |
if (a[1] < b[1]) return 1; | |
if (a[1] > b[1]) return -1; | |
return 0; | |
// then take the resulting array and map it into a one-liner in the output format | |
}).map(function(o){ | |
return o[1]+': '+o[0]; | |
// then take the array and join separated by newline | |
}).join('\n') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment