Merge pull request #150 from rpolishchuk/rp-fix-135

Change configuration order to sytem-then-user
This commit is contained in:
Radovan Garabík 2020-06-02 21:25:18 +02:00 committed by GitHub
commit 01a21de7fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 21 deletions

37
grc
View File

@ -81,38 +81,33 @@ if stdoutf == 1:
if use_pty:
import pty
conffile = None
if cfile == "":
home = os.environ.get('HOME')
xdg = os.environ.get('XDG_CONFIG_HOME')
if not xdg and home:
xdg = home + '/.config'
conffilenames = []
conffilenames = ['/etc/grc.conf', '/usr/local/etc/grc.conf']
if xdg:
conffilenames += [xdg + '/grc/grc.conf']
if home:
conffilenames += [home + '/.grc/grc.conf']
conffilenames += ['/usr/local/etc/grc.conf', '/etc/grc.conf']
for i in conffilenames:
# test if conffile exists, it can be also a pipe
if os.path.exists(i) and not os.path.isdir(i):
conffile = i
break
regexplist = []
if conffile:
f = open(conffile, "r")
while 1:
l = f.readline()
if l == "":
break
if l[0] == "#" or l[0] == '\012':
continue
regexp = l.strip()
if re.search(regexp, ' '.join(args)):
cfile = f.readline().strip()
break
for conffile in conffilenames:
# test if conffile exists, it can be also a pipe
if os.path.exists(conffile) and not os.path.isdir(conffile):
f = open(conffile, "r")
while 1:
l = f.readline()
if l == "":
break
if l[0] == "#" or l[0] == '\012':
continue
regexp = l.strip()
if re.search(regexp, ' '.join(args)):
cfile = f.readline().strip()
break
signal.signal(signal.SIGINT, catch_signal)