Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Configure File Support - Version 2 #709

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

decaff
Copy link

@decaff decaff commented Jul 3, 2015

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

Implementation is based on PR ggreer#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
@aisapatino
Copy link

@ggreer thoughts on this? or some other way of supporting default options? #574

@deivid-rodriguez
Copy link

@ggreer Are you considering this?

@vampolo
Copy link

vampolo commented Apr 20, 2016

@ggreer fell on this today. any chance it will be merged?

@rosshadden
Copy link

rosshadden commented May 10, 2016

👍 This would be a lot better than aliasing ag to ag --with --various --options.

@lgarron
Copy link
Contributor

lgarron commented Jun 10, 2016

I would also love to see a defaults file. I have had trouble switching to ag instead of grep because I kept missing results – I just found out today I should always pass in the --hidden flag to help with that (and then use .agignore to exclude.git dirs).

For what it's worth, I got here via (!):

  1. Google search for "the_silver_searcher default arguments" (second result)
  2. Environment variable for default parameters #79 ("Actually, I've changed my mind about this feature. It really seems like aliases are the way to go.")
  3. support for AG_OPTIONS #121
  4. Add support for ~/.agrc default config options #257
  5. Ag config file support implemented #701

It would be nice if the file could be located either at ~/.agrc or under ~/.config/, as git and many other tools allow. But I guess .agignore doesn't support that either, and any control would be better than none.

As a user of fish, I try not to implement default argument handling in my shell configuration itself. A configuration file is more consistent with all my other shell tools.

@kugel-
Copy link

kugel- commented Jun 24, 2016

@ggreer please consider this. I'm coming from ack and truly miss this.

@stfl
Copy link

stfl commented Jul 14, 2016

+1

@ZyX-I
Copy link

ZyX-I commented Jul 27, 2016

I would say that current PR has some flaws:

  1. ~/.agrc should not be present present at all: XDG spec does not expect this.
  2. Yet I would suggest to use ./.agrc, ../.argrc, ../../.agrc, etc; in many cases this would also pickup ~/.agrc.
  3. Need a command-line option to ignore agrc files completely. Alternatively: command-line option to specify one agrc file which will be used in place of all defaults, AGRC_PATH is not needed much in this case.
  4. System-wide configuration should be using ${XDG_CONFIG_DIRS:-/etc/xdg}, $xdg_config_dir/agrc (XDG_CONFIG_DIRS is a list): XDG spec also cares about this.

.nf
1. \fIPath specified in $AGRC_PATH\fR
.br
2. \fI$XDG_CONFIG_HOME/agrc\fR
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would strongly suggest this not be put directly into the XDG_CONFIG_HOME. Instead, I would suggest using a subdirectory of XDG_CONFIG_HOME the same way git and others do: $XDG_CONFIG_HOME/ag/agrc. It's been suggested in #1020 that the ignore lookup should also conform to XDG spec, and having these all in a single directory makes more sense than proliferating directly in the root of $XDG_CONFIG_HOME

trinitronx added a commit to trinitronx/the_silver_searcher that referenced this pull request Jun 13, 2023
trinitronx added a commit to trinitronx/the_silver_searcher that referenced this pull request Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants