--- /dev/null
+USING: tools.deploy.config ;
+H{
+ { deploy-name "grep" }
+ { deploy-ui? f }
+ { deploy-c-types? t }
+ { deploy-console? t }
+ { deploy-unicode? f }
+ { "stop-after-last-window?" t }
+ { deploy-io 3 }
+ { deploy-reflection 6 }
+ { deploy-word-props? t }
+ { deploy-math? t }
+ { deploy-threads? t }
+ { deploy-word-defs? t }
+}
--- /dev/null
+
+USING: kernel fry io io.files io.encodings.ascii sequences
+regexp command-line namespaces ;
+
+IN: tools.grep
+
+! TODO: getopt
+! TODO: color
+! TODO: case-insensitive
+
+: grep-lines ( regexpt -- )
+ '[ dup _ matches? [ print ] [ drop ] if ] each-line ;
+
+: grep-file ( pattern filename -- )
+ ascii [ grep-lines ] with-file-reader ;
+
+: grep-usage ( -- )
+ "Usage: factor grep.factor <pattern> [<file>...]" print ;
+
+: run-grep ( -- )
+ command-line get [
+ grep-usage
+ ] [
+ unclip ".*" dup surround <regexp> swap [
+ grep-lines
+ ] [
+ [ grep-file ] with each
+ ] if-empty
+ ] if-empty ;
+
+MAIN: run-grep