Skip to content

Commit

Permalink
Add option --list-file-types
Browse files Browse the repository at this point in the history
This patch documents the file types which were made searchable in ggreer#283
  • Loading branch information
Neil McPhail authored and greg0ire committed Apr 23, 2014
1 parent ac1e7e4 commit 21d34f0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
15 changes: 12 additions & 3 deletions doc/ag.1
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "AG" "1" "September 2013" "" ""
.TH "AG" "1" "January 2014" "" ""
.
.SH "NAME"
\fBag\fR \- The Silver Searcher\. Like ack, but faster\.
.
.SH "SYNOPSIS"
\fBag\fR [\fIoptions\fR] PATTERN [PATH]
\fBag\fR [\fIfile\-type\fR] [\fIoptions\fR] PATTERN [PATH]
.
.SH "DESCRIPTION"
Recursively search for PATTERN in PATH\. Like grep or ack, but faster\.
Expand Down Expand Up @@ -151,6 +151,12 @@ Recursively search for PATTERN in PATH\. Like grep or ack, but faster\.
\~\~\~\~ Only print filenames that don\'t contain matches\.
.
.P
\fB\-\-list\-file\-types\fR:
.
.br
\~\~\~\~ See \fBFILE TYPES\fR below\.
.
.P
\fB\-m \-\-max\-count NUM\fR:
.
.br
Expand Down Expand Up @@ -237,7 +243,10 @@ Recursively search for PATTERN in PATH\. Like grep or ack, but faster\.
.br
\~\~\~\~ Only match whole words\.
.
.P
.SH "FILE TYPES"
It is possible to restrict the types of files searched\. For example, passing \fB\-\-html\fR as the \fBfile\-types\fR parameter will search only files with the extensions \fBhtm\fR, \fBhtml\fR, \fBshtml\fR or \fBxhtml\fR\. For a list of supported \fBfile\-types\fR run \fBag \-\-list\-file\-types\fR\.
.
.SH "IGNORING FILES"
By default, ag will ignore files matched by patterns in \.gitignore, \.hgignore, or \.agignore\. These files can be anywhere in the directories being searched\. Ag also ignores files matched by the svn:ignore property in subversion repositories\. Finally, ag looks in $HOME/\.agignore for ignore patterns\. Binary files are ignored by default as well\.
.
.P
Expand Down
8 changes: 7 additions & 1 deletion doc/ag.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ag(1) -- The Silver Searcher. Like ack, but faster.

## SYNOPSIS

`ag` [<options>] PATTERN [PATH]
`ag` [<file-type>] [<options>] PATTERN [PATH]

## DESCRIPTION

Expand Down Expand Up @@ -57,6 +57,8 @@ Recursively search for PATTERN in PATH. Like grep or ack, but faster.
Only print filenames containing matches, not matching lines. An empty query will print all files that would be searched.
* `-L --files-without-matches`:
Only print filenames that don't contain matches.
* `--list-file-types`:
See `FILE TYPES` below.
* `-m --max-count NUM`:
Skip the rest of a file after NUM matches. Default is 10,000.
* `--no-numbers`:
Expand Down Expand Up @@ -87,6 +89,10 @@ Recursively search for PATTERN in PATH. Like grep or ack, but faster.
* `-w --word-regexp`:
Only match whole words.

## FILE TYPES

It is possible to restrict the types of files searched. For example, passing `--html` as the `file-types` parameter will search only files with the extensions `htm`, `html`, `shtml` or `xhtml`. For a list of supported `file-types` run `ag --list-file-types`.

## IGNORING FILES

By default, ag will ignore files matched by patterns in .gitignore, .hgignore, or .agignore. These files can be anywhere in the directories being searched. Ag also ignores files matched by the svn:ignore property in subversion repositories. Finally, ag looks in $HOME/.agignore for ignore patterns. Binary files are ignored by default as well.
Expand Down
3 changes: 2 additions & 1 deletion doc/generate_man.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ BEGIN{
} else if (first_4_chars == " ") { # we are in a description line
printf("&nbsp;&nbsp;&nbsp;&nbsp; %s\n", substr($0, 5));
first_item_in_list_of_options = 1;
} else if (first_4_chars == "## I") { # reached the end of #OPTIONS part
} else if (first_4_chars == "## F") { # reached the end of #OPTIONS part
in_options_block = 0;
print $0;
} else {
print $0;
}
Expand Down
25 changes: 24 additions & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const char *color_path = "\033[1;32m"; /* bold green */
/* TODO: try to obey out_fd? */
void usage(void) {
printf("\n");
printf("Usage: ag [OPTIONS] PATTERN [PATH]\n\n");
printf("Usage: ag [FILE-TYPE] [OPTIONS] PATTERN [PATH]\n\n");

printf(" Recursively search for PATTERN in PATH.\n");
printf(" Like grep or ack, but faster.\n\n");
Expand Down Expand Up @@ -83,6 +83,13 @@ Search Options:\n\
-w --word-regexp Only match whole words\n\
-z --search-zip Search contents of compressed (e.g., gzip) files\n\
\n");
printf("File Types:\n\
The search can be restricted to certain types of files. Example:\n\
ag --html needle\n\
- Searches for 'needle' in files with suffix .htm, .html, .shtml or .xhtml.\n\
\n\
For a list of supported file types run:\n\
ag --list-file-types\n\n");
}

void print_version(void) {
Expand Down Expand Up @@ -146,6 +153,7 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) {
int group = 1;
int help = 0;
int version = 0;
int list_file_types = 0;
int opt_index = 0;
const char *home_dir = getenv("HOME");
char *ignore_file_path = NULL;
Expand Down Expand Up @@ -189,6 +197,7 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) {
{ "ignore-case", no_argument, NULL, 'i' },
{ "invert-match", no_argument, &opts.invert_match, 1 },
{ "line-numbers", no_argument, &opts.print_line_numbers, 2 },
{ "list-file-types", no_argument, &list_file_types, 1 },
{ "literal", no_argument, NULL, 'Q' },
{ "match", no_argument, &useless, 0 },
{ "max-count", required_argument, NULL, 'm' },
Expand Down Expand Up @@ -443,6 +452,20 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) {
exit(0);
}

if (list_file_types) {
int i;
printf("The following file types are supported:\n");
for (i = 0; i < LANG_COUNT; i++) {
printf(" --%s\n ", langs[i].name);
int j;
for (j = 0; j < MAX_EXTENSIONS && langs[i].extensions[j]; j++) {
printf(" .%s", langs[i].extensions[j]);
}
printf("\n\n");
}
exit(0);
}

if (needs_query && argc == 0) {
log_err("What do you want to search for?");
exit(1);
Expand Down

0 comments on commit 21d34f0

Please sign in to comment.