From 8fc1ad5220916d5a464335e8e7aa9ff185948994 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Wed, 21 Feb 2024 09:23:29 +0100 Subject: [PATCH] Warn about ignoring XDG_CONFIG_HOME and ~/.config/osc/oscrc if ~/.oscrc exists --- osc/conf.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/osc/conf.py b/osc/conf.py index a302e7e5..a581b1aa 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -65,6 +65,7 @@ from urllib.parse import urlsplit from . import credentials from . import OscConfigParser from . import oscerr +from .output import tty from .util import xdg from .util.helper import raw_input from .util.models import * @@ -2056,11 +2057,17 @@ def identify_conf(): if 'OSC_CONFIG' in os.environ: return os.environ.get('OSC_CONFIG') - if os.path.exists(os.path.expanduser('~/.oscrc')): - return '~/.oscrc' - conffile = os.path.join(xdg.XDG_CONFIG_HOME, "osc", "oscrc") + if os.path.exists(os.path.expanduser("~/.oscrc")) or os.path.islink(os.path.expanduser("~/.oscrc")): + if "XDG_CONFIG_HOME" in os.environ: + print(f"{tty.colorize('WARNING', 'yellow,bold')}: Ignoring XDG_CONFIG_HOME env, loading an existing config from '~/.oscrc' instead", file=sys.stderr) + print(" To fix this, move the existing '~/.oscrc' to XDG location such as '~/.config/osc/oscrc'", file=sys.stderr) + elif os.path.exists(os.path.expanduser(conffile)): + print(f"{tty.colorize('WARNING', 'yellow,bold')}: Ignoring config '{conffile}' in XDG location, loading an existing config from ~/.oscrc instead", file=sys.stderr) + print(" To fix this, remove '~/.oscrc'", file=sys.stderr) + return '~/.oscrc' + return conffile