From 4f4c779885aa2953234cc59f84a9b398fb953ce0 Mon Sep 17 00:00:00 2001 From: Aaron Gable Date: Wed, 16 Jun 2021 14:25:44 -0700 Subject: [PATCH] Prefer $XDG_CONFIG_HOME/ag/ignore over ~/.agignore Fixes https://github.com/ggreer/the_silver_searcher/issues/1020 --- src/options.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/options.c b/src/options.c index 2145b33bb..fe2de17ce 100644 --- a/src/options.c +++ b/src/options.c @@ -219,6 +219,7 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) { int opt_index = 0; char *num_end; const char *home_dir = getenv("HOME"); + const char *config_dir = getenv("XDG_CONFIG_HOME"); char *ignore_file_path = NULL; int accepts_query = 1; int needs_query = 1; @@ -685,10 +686,15 @@ void parse_options(int argc, char **argv, char **base_paths[], char **paths[]) { exit(1); } - if (home_dir && !opts.search_all_files) { - log_debug("Found user's home dir: %s", home_dir); - ag_asprintf(&ignore_file_path, "%s/.agignore", home_dir); - load_ignore_patterns(root_ignores, ignore_file_path); + if (!opts.search_all_files) { + if (config_home) { + ag_asprintf(&ignore_file_path, "%s/%s", config_home, "ag/ignore"); + } else if (home_dir) { + ag_asprintf(&ignore_file_path, "%s/%s", home_dir, ".agignore"); + } + if (ignore_file_path) { + load_ignore_patterns(root_ignores, ignore_file_path); + } free(ignore_file_path); }