Support the XDG Base Directory Specification

This commit is contained in:
Leonardo Brondani Schenkel 2016-09-24 16:15:36 +02:00
parent 021439191c
commit 0928d0b936
2 changed files with 27 additions and 7 deletions

15
grc
View File

@ -71,10 +71,17 @@ if stdoutf == 1:
conffile = None
if cfile == "":
home = []
if 'HOME' in os.environ:
home = [os.environ['HOME']+"/.grc/grc.conf"]
conffilenames = home + ["/etc/grc.conf"]
home = os.environ.get('HOME')
xdg = os.environ.get('XDG_CONFIG_HOME')
if not xdg and home:
xdg = home + '/.config'
conffilenames = []
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:
if os.path.isfile(i):
conffile = i

19
grcat
View File

@ -84,9 +84,22 @@ def get_colour(x):
home = []
conffile = None
if 'HOME' in os.environ:
home = [os.environ['HOME']+"/.grc/"]
conffilepath = [""] + home + ["/usr/local/share/grc/", "/usr/share/grc/"]
xdg_config = os.environ.get('XDG_CONFIG_HOME')
xdg_data = os.environ.get('XDG_DATA_HOME')
home = os.environ.get('HOME')
if home and not xdg_config:
xdg_config = home + '/.config'
if home and not xdg_data:
xdg_data = home + '/.local/share'
conffilepath = [""]
if xdg_data:
conffilepath += [xdg_data + '/grc/']
if xdg_config:
conffilepath += [xdg_config + '/grc/']
if home:
conffilepath += [home + '/.grc/']
conffilepath += ['/usr/local/share/grc/', '/usr/share/grc/']
if len(sys.argv) != 2:
sys.stderr.write("You are not supposed to call grcat directly, but the usage is: grcat conffile\n")
sys.exit(1)