Skip to content

Instantly share code, notes, and snippets.

@danking
Last active August 29, 2015 14:00
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 danking/11101463 to your computer and use it in GitHub Desktop.
Save danking/11101463 to your computer and use it in GitHub Desktop.
#lang shill/cap
require shill/contracts
shill/io;
provide [find : forall [X:+path,+lookup,+contents] . [f: X]
[filter: [_: X] -> boolean?]
[cmd: [_: X] -> any]
->
any ];
# filter functions
provide [name : [_: string?] -> [_ : pathable] -> boolean?]
[fullname : [_: string?] -> [_ : pathable] -> boolean?];
# actions
provide [grep : [regexp : or/c(string?, regexp?)]
[out : writeable?] ->
[file : file/c(+read, +path)]
->
any ];
val pathable = or/c(file/c(+path),dir/c(+path));
val ls = fun(dir) { contents(dir); };
val find = fun(f, filter, cmd) {
if and(file?(f),filter(f)) then
cmd(f);
# if f is a directory, recurse on its contents
if dir?(f) then
for g in ls(f) do {
val fc = lookup(f,g);
if not(sys-error?(fc)) then
find(fc, filter, cmd);
};
};
val grep = fun(regexp, out) {
fun (file) {
val contents = read(file);
val matches = regexp-match*(regexp, contents);
for match in matches do {
fwrite(out, "~a: ~a\n", path(file), match);
}
};
};
val name = fun(r) {
val re = regexp(r);
fun(f) regexp-match?(re, shortname(path(f)));
};
val shortname = fun(path) {
path-element->string(last(explode-path(string->path(path))));
};
val fullname = fun(r) {
val re = regexp(r);
fun(f) regexp-match?(re, path(f));
};
@danking
Copy link
Author

danking commented Apr 20, 2014

    /usr/bin/time -al -o ${LOG_PATH}/times \
        find . -name '*.c' -exec grep -Hi torvalds '{}' ';' > ${LOG_PATH}/log.$i

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment