about summary refs log tree commit homepage
path: root/lib/PublicInbox/Config.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/Config.pm')
-rw-r--r--lib/PublicInbox/Config.pm10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index d91c28a9..9ba4ad32 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -3,12 +3,13 @@
 package PublicInbox::Config;
 use strict;
 use warnings;
+use File::Path::Expand qw/expand_filename/;
 
 # returns key-value pairs of config directives in a hash
 sub new {
         my ($class, $file) = @_;
 
-        local $ENV{GIT_CONFIG} = $file;
+        local $ENV{GIT_CONFIG} = defined $file ? $file : default_file();
 
         my @cfg = `git config -l`;
         $? == 0 or die "git config -l failed: $?\n";
@@ -37,4 +38,11 @@ sub lookup {
         \%rv;
 }
 
+sub default_file {
+        my $f = $ENV{PI_CONFIG};
+        return $f if defined $f;
+        my $pi_dir = $ENV{PI_DIR} || expand_filename('~/.public-inbox/');
+        "$pi_dir/config";
+}
+
 1;