Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mayanksuman/eg into mayan…
Browse files Browse the repository at this point in the history
…ksuman-master
  • Loading branch information
srsudar committed Apr 13, 2020
2 parents 96142a7 + ada58aa commit 486a054
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ eg --examples-dir='the/default/dir' --custom-dir='my/fancy/dir' find
```

Instead of doing this every time, you can define a configuration file. By
default it is expected to live in `~/.egrc`. It must begin with a section
default it is expected to live in `$XDG_CONFIG_HOME/eg.conf`
(usually `~/.config/eg.conf`) or `~/.egrc`. It must begin with a section
called `eg-config` and can contain two keys: `custom-dir` and `examples-dir`.
Here is an example of a valid config file:

Expand Down
12 changes: 11 additions & 1 deletion eg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
SQUEEZE = 'squeeze'
EDITOR_CMD = 'editor-cmd'

# Config location based on XDG speciification
if 'XDG_CONFIG_HOME' in os.environ:
configdir = os.environ['XDG_CONFIG_HOME']
else:
configdir = os.path.join('~', '.config')
XDG_CONFIG_EGCONF_PATH = os.path.join(configdir, 'eg.conf')
# if config file not exist at XDG_CONFIG_EGRC_PATH then reassign None
if ~os.path.isfile(XDG_CONFIG_EGCONF_PATH):
XDG_CONFIG_EGCONF_PATH = None

# A basic struct containing configuration values.
# examples_dir: path to the directory of examples that ship with eg
# custom_dir: path to the directory where custom examples are found
Expand Down Expand Up @@ -159,7 +169,7 @@ def get_egrc_config(cli_egrc_path):
cli_egrc_path: the path to the egrc as given on the command line via
--config-file
"""
resolved_path = get_priority(cli_egrc_path, DEFAULT_EGRC_PATH, None)
resolved_path = get_priority(cli_egrc_path, XDG_CONFIG_EGCONF_PATH, DEFAULT_EGRC_PATH)
expanded_path = get_expanded_path(resolved_path)

# Start as if nothing was defined in the egrc.
Expand Down

0 comments on commit 486a054

Please sign in to comment.