about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorRory Bradford <roryrjb@gmail.com>2020-08-11 14:44:46 +0100
committerRory Bradford <roryrjb@gmail.com>2020-08-11 14:44:46 +0100
commitb4f90ecd3cacf7442e693548c13d79137ba1faa0 (patch)
treeab5883277077b8d7e59761c94995aec9fc432baf
parentdc4c58dee58d24d582d6d89cc29311652340e46a (diff)
downloadrf-b4f90ecd3cacf7442e693548c13d79137ba1faa0.tar.gz
Add change root directory option
Signed-off-by: Rory Bradford <roryrjb@gmail.com>
-rw-r--r--rf.15
-rw-r--r--rf.c9
2 files changed, 12 insertions, 2 deletions
diff --git a/rf.1 b/rf.1
index b4eab3c..9f58417 100644
--- a/rf.1
+++ b/rf.1
@@ -5,6 +5,7 @@ rf \- a tiny and simple file finder
 
 .SH SYNOPSIS
 .SY rf
+.OP \-d directory
 .OP \-lsvw
 .OP pattern ...
 
@@ -14,6 +15,10 @@ substring) patterns, while respecting any ignore rules in \fBrfignore\fR files.
 
 .SH OPTIONS
 .TP
+.BI \-d directory
+Search from specified directory, otherwise defaults to current working directory.
+.
+.TP
 .BI \-l count
 Limit to specified matches count.
 .
diff --git a/rf.c b/rf.c
index bee1ea9..14acc9d 100644
--- a/rf.c
+++ b/rf.c
@@ -38,7 +38,8 @@ static void usage(char *error) {
 		fprintf(stderr, "Error: %s\n\n", error);
 	}
 
-	fprintf(stderr, "usage: %s [-lsvw] pattern ...\n", __progname);
+	fprintf(
+		stderr, "usage: %s [-d directory] [-lsvw] pattern ...\n", __progname);
 }
 
 static int is_child(char *dirname) {
@@ -179,6 +180,10 @@ int main(int argc, char **argv) {
 
 	while ((ch = getopt(argc, argv, "l:svw")) > -1) {
 		switch (ch) {
+		case 'd':
+			root = optarg;
+			break;
+
 		case 'h':
 			usage(NULL);
 			exit(EXIT_SUCCESS);
@@ -249,7 +254,7 @@ int main(int argc, char **argv) {
 			patterns[i++] = argv[optind++];
 		}
 
-		if (recurse_find(patterns, &pattern_count, ".", &switches)) {
+		if (recurse_find(patterns, &pattern_count, root, &switches)) {
 			/* finished early because we reached the limit */
 		};