Add support for ~/.agrc default config options #257

Closed
wants to merge 1 commit into
from

Projects

None yet
@schlosna
schlosna commented Sep 7, 2013

I can't live without my default options, so this adds support for ~/.agrc similar to .ackrc

  • Load .agrc configuration file from user's home directory if available.
  • CLI options take precedence over .agrc options
@schlosna schlosna Add support for ~/.agrc default config options
* Load .agrc configuration file from user's home directory if available.
* CLI options take precedence over .agrc options
de160e3
@Julian
Julian commented Sep 8, 2013

Nice. See also #121.

XDG conformity and/or an envvar would be nice to have.

@Zearin
Contributor
Zearin commented Sep 9, 2013

XDG conformity and/or an envvar would be nice to have.

👍

  • XDG conformance: Check for ~/.config/.agrc before ~/.agrc
  • Bonus points: Check an environment variable first, which allows users to specify a custom location for their .agrc file.

For most command line tools, I use this to point them to the dotfiles in my home ~/.config/ directory, if they don’t support it “out of the box”. Using an environment variables to point to a config file is one of the most flexible features a command-line tool can have. I love that feature. ❤️

@majutsushi

This is not quite correct, for XDG conformance the location should be $XDG_CONFIG_HOME/agrc (also note the missing dot). ~/.config should only be used if the variable is not set or empty, see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html. This essentially also satisfies your second point.

@metellius

Any progress here? I really want to use this config to experiment with setting filetype shortcuts like ack has (ie, --cpp, which would be an alias for -G\ .h|.cpp)

@blueyed
Contributor
blueyed commented Jan 3, 2014

I would like to have an .agrc file for different parts of the directory subtrees, e.g. to use -U inside of ~/.vim/bundle, where issue #168 might be a problem.

@ainformatico
Contributor

would be great to have this file! it's better to have a file with all the configuration rather than a lot of aliases.

@wincent wincent added a commit to wincent/wincent that referenced this pull request Apr 12, 2014
@wincent wincent ag: use the pager all the time
Would ideally have an .agrc file, like you can have an .ackrc file with
Ack, but that's not supported yet:

  ggreer/the_silver_searcher#257

So, use an alias instead.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
186b764
@nhooey
nhooey commented Apr 18, 2014

Can someone either review this change or merge it?

@eevee
eevee commented May 9, 2014

Should /etc/agrc also work? ack 2.0 supports /etc/ackrc.

@Zearin
Contributor
Zearin commented May 9, 2014

Hmm. Let me see if I have this right…

  1. /etc/agrc
  2. /usr/local/etc/agrc
  3. $XDG_CONFIG_HOME/agrc
  4. ~/.agrc
  5. Environment variable specifying config file
  6. Command-line options

Does that cover everything?


(Edit: Removed leading dot, as mentioned by @majutsushi)

@ainformatico
Contributor

@Zearin I think that's enough and covers all the general cases.

@djanowski

@ggreer Any updates on this or the alternative #121?

@bwiggs
bwiggs commented Aug 14, 2014

+1 for this, looking for a way to add -i (ignore case) as a default option without using an alias.

@ggreer ggreer added the options label Feb 3, 2015
@djanowski

@schlosna Can you merge current master? Maybe that way we have some chance of getting this upstream?

@decaff decaff added a commit to decaff/the_silver_searcher that referenced this pull request Jun 24, 2015
@decaff decaff Add support for config files, based on discussion in #257
I took David Schlosnagle's code (@schlosna) and adapted it to follow the many
of the suggestions discussed in issue #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.
f4336d8
@decaff
decaff commented Jun 24, 2015

I moved @schlosna's code into 2 new source files (makes it easier to merge) and added the config file hierarchy listed above by @Zearin . Commit is here . Hope this helps.

@blueyed
Contributor
blueyed commented Jun 24, 2015

@decaff
Seems to be worth a separate / follow-up PR then?!

@decaff
decaff commented Jun 24, 2015

Umm, I'm new to github. So, I'm unfamiliar with the protocol for things like this. I assume that Geoff will merge if he approves and if he has time to review the code.

@blueyed
Contributor
blueyed commented Jun 25, 2015

@decaff
Your commit will be lost/forgotten about probably, and this PR here appears to be stale.
I therefore think that creating a new PR with your commit (in a separate branch) is the way to go.

@nhooey
nhooey commented Jun 25, 2015

If you could let us all know what the new pull request is, that would be great. I think we're all really excited about this change.

@decaff
decaff commented Jun 25, 2015

Hmmm, I can barely chew gum and walk when it comes to git. So, is this the desired outcome?

  1. @decaff creates a new, local branch off Geoff's master
  2. I merge just the .agrc changes
  3. Push the branch back up to github
  4. Come back here and announce the branch

Is this what is desired?

@blueyed
Contributor
blueyed commented Jun 25, 2015

@decaff
Yes, that's what I've meant. Keeping it in a separate branch makes it easier / possible to distinguish feature sets.

But given how this PR has rotten over the months, without any feedback from @ggreer you should not expect too much from it (in the near future).. :/
However, it's still better than only having linked a commit in a comment.

After all, your effort combines the efforts from this PR and should be seen / handled as its successor.

Thanks!

@blueyed
Contributor
blueyed commented Jun 25, 2015

@decaff
About your 2nd point: you would basically git cherry-pick your commit into the new branch - I'm not sure that's what you've meant.

@decaff
decaff commented Jun 25, 2015

I'll give it a shot.

@decaff decaff added a commit to decaff/the_silver_searcher that referenced this pull request Jun 25, 2015
@decaff decaff Add support for config files, based on discussion in #257
I took David Schlosnagle's code (@schlosna) and adapted it to follow many
of the suggestions discussed in issue #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) above, 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.
5d50f59
@decaff
decaff commented Jun 25, 2015

That was really unpleasant. Branch has been created . Found a bug in the line counting code while testing my manual merge. Fixed same.

@blueyed
Contributor
blueyed commented Jun 25, 2015

@decaff

That was really unpleasant.

Why?

Branch has been created

But no PR yet? The link to the branch appears to be: master...decaff:config-file-support

Found a bug in the line counting code while testing my manual merge. Fixed same.

But not in a separate commit?
Wouldn't it be a bugfix for ag in general (for its master branch)? Then it should be a separate PR/issue/commit.

@decaff
decaff commented Jun 25, 2015

Bug in my line counting code in ag_rc.c .

Unpleasant because I have no idea how to use git, beyond saving changes and pushing stuff to github. I eventually gave up and merged the changes by hand. Better safe than trashing my local repository.

I'll push the button for a pull request...

@blueyed
Contributor
blueyed commented Jun 25, 2015

Unpleasant because I have no idea how to use git, beyond saving changes and pushing stuff to github

You'll hopefully get used to it.

The basic steps would have been (from the origin/master branch):

# Create your branch
% git checkout -b config-file-support
# Cherry-pick your previous commit
% git cherry-pick f4336d8
# Register your origin/fork with Git
% git remote add decaff https://github.com/decaff/the_silver_searcher
# Push your branch to your fork.
% git push decaff config-file-support

But you got that figured out.
I recommend using https://github.com/github/hub/ for advanced commands with git when used with Github.

@blueyed
Contributor
blueyed commented Jun 25, 2015

Given that there's #701 now, this PR could be closed probably. (please note that I have not looked at the code)

@schlosna
schlosna commented Jul 2, 2015

Thanks @decaff , closing this PR in favor or #701.

@schlosna schlosna closed this Jul 2, 2015
@decaff decaff added a commit to decaff/the_silver_searcher that referenced this pull request Jul 3, 2015
@decaff decaff Add Configure File Support
Implementation is based on PR #257, authored by David Schlosnagle.

Ag reads OPTIONS from one of several configuration files.  Ag processes "config
file"  options  before  command-line options.  The config file format is very
simple:

    # 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 Config File
        ==========================
        # 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

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.

Ag reads configuration information from a number of possible locations,
in the following order (first file found is used, all others ignored):

    1.   Path specified in $AGRC_PATH
    2.   $XDG_CONFIG_HOME/agrc
    3.   ~/.agrc
    4.   /usr/local/etc/agrc
    5.   /etc/agrc
9c23228
@decaff
decaff commented Jul 3, 2015

PR #709 supersedes #701 . 709 is up-to-date with master and passes the clang format tests.

@lgarron lgarron added a commit to lgarron/dotfiles that referenced this pull request Jun 11, 2016
@lgarron lgarron [ag] Make `ag` search hidden files and folders (except `.git`).
`ag` now expands to `ag --hidden` while typing, to work around ggreer/the_silver_searcher#257
0605843
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment