Skip to content

Commit

Permalink
Add support for config files, based on discussion in ggreer#257
Browse files Browse the repository at this point in the history
I took David Schlosnagle's code (@schlosna) and adapted it to follow the many
of the suggestions discussed in issue ggreer#257.  Changes between David's code and
my adaptation:

1) Almost 100% of the code lives in 2 new source files.  src/options.c
   is not touched.
2) Consequently, merging this code with current forks is pretty easy.
3) Also due to #1, if you know C, you can hack the config file features
   to your heart's content.
4) Multiple config file locations are tested at startup (first found file
   wins, all others ignored). Here are the locations and order of access:

	1.   Path specified in $AGRC_PATH
	2.   $XDG_CONFIG_HOME/agrc
	3.   ~/.agrc
	4.   /usr/local/etc/agrc
	5.   /etc/agrc

5) Config file format:

	# this is a comment => inline comments not supported
	# blank lines okay as well

	--long-option[=value]
	-short-option[=value]
	--long-option[ value]
	-short-option[ value]

	# And special keywords (of which there is only one)
	list

Actual Example File (mine)
	# set up nice colors for a white terminal bkgnd...

	# bold blue
	--color-line-number=1;34
	# black with grey bkgnd
	--color-match=30;47
	# green
	--color-path=32

The features and paths are documented in the ag man page.
  • Loading branch information
decaff committed Jun 24, 2015
1 parent f46c0d5 commit f4336d8
Show file tree
Hide file tree
Showing 6 changed files with 427 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
@@ -1,7 +1,7 @@
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}

bin_PROGRAMS = ag
ag_SOURCES = src/ignore.c src/ignore.h src/log.c src/log.h src/options.c src/options.h src/print.c src/print_w32.c src/print.h src/scandir.c src/scandir.h src/search.c src/search.h src/lang.c src/lang.h src/util.c src/util.h src/decompress.c src/decompress.h src/uthash.h src/main.c
ag_SOURCES = src/ignore.c src/ignore.h src/log.c src/log.h src/options.c src/options.h src/print.c src/print_w32.c src/print.h src/scandir.c src/scandir.h src/search.c src/search.h src/lang.c src/lang.h src/util.c src/util.h src/decompress.c src/decompress.h src/uthash.h src/main.c src/ag_rc.c src/ag_rc.h
ag_LDADD = ${PCRE_LIBS} ${LZMA_LIBS} ${ZLIB_LIBS} $(PTHREAD_LIBS)

dist_man_MANS = doc/ag.1
Expand Down
1 change: 1 addition & 0 deletions Makefile.w32
Expand Up @@ -14,6 +14,7 @@ SRCS = \
src/scandir.c \
src/search.c \
src/util.c \
src/ag_rc.c \
src/print_w32.c
OBJS = $(subst .c,.o,$(SRCS))

Expand Down
76 changes: 75 additions & 1 deletion doc/ag.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "AG" "1" "February 2015" "" ""
.TH "AG" "1" "June 2015" "" ""
.
.SH "NAME"
\fBag\fR \- The Silver Searcher\. Like ack, but faster\.
Expand Down Expand Up @@ -323,6 +323,80 @@ ag 'abc[^=\\n]+=' test.c
3: *abc = 700;
.RE
.
.SH "CONFIGURATION FILES"
Ag reads \fBOPTIONS\fR from one of several configuration
files. Ag processes "config file" options \fBbefore\fR command-line
options. The config file format is very simple:
.P
.RS 4
# this is a comment => inline comments not supported
.br
# blank lines okay as well
.P
.br
\-\-long-option[=value]
.br
\-short-option[=value]
.br
\-\-long-option[ value]
.br
\-short-option[ value]
.P
.br
# And special keywords (of which there is only one)
.br
list
.RE
.P
Actual Example Config File
.br
==========================
.br
# set up nice colors for a white terminal bkgnd...
.P
.br
# bold blue
.br
\-\-color\-line\-number=1;34
.br
# black with grey bkgnd
.br
\-\-color\-match=30;47
.br
# green
.br
\-\-color\-path=32
.P
If the keyword "list" is included in a config file,
ag dumps the contents of argv[] on stdout. This is useful
for debugging config file errors that cause ag to output a usage
message and then silently exit.
.
.SH "CONFIGURATION FILE LOCATIONS"
Ag reads configuration information from a number of possible locations, in
the following order (first file found is used, all others ignored):
.RS
.P
.nf
1. \fIPath specified in $AGRC_PATH\fR
.br
2. \fI$XDG_CONFIG_HOME/agrc\fR
.br
3. \fI~/.agrc\fR
.br
4. \fI/usr/local/etc/agrc\fR
.br
5. \fI/etc/agrc\fR
.fi
.RE
.
.SH "ENVIRONMENT VARIABLES"
.
.TP
.
\fBAGRC_PATH\fR
Specifies a complete path to an ag configuration file.
.
.SH "SEE ALSO"
.BR grep(1),
.BR pcre(3),
Expand Down

0 comments on commit f4336d8

Please sign in to comment.