1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-19 04:21:14 +00:00

fix: new config dirs created in $HOME/.config/thefuck instead of $CWD

fix: use correct path in warning message when XDG_CONFIG_HOME defined
This commit is contained in:
Kyle Thrift 2016-08-21 15:59:16 -04:00
parent 070bb2ff28
commit 0bd3e85e08

View File

@ -40,16 +40,21 @@ class Settings(dict):
settings_file.write(u'# {} = {}\n'.format(*setting)) settings_file.write(u'# {} = {}\n'.format(*setting))
def _get_user_dir_path(self): def _get_user_dir_path(self):
# for backward compatibility, use `~/.thefuck` if it exists """returns Path object representing the user config resource"""
legacy_user_dir = Path('~/.thefuck').expanduser() xdg_config_home = os.getenv("XDG_CONFIG_HOME", "~/.config")
user_dir_modern = Path(xdg_config_home, 'thefuck').expanduser()
user_dir_legacy = Path('~', '.thefuck').expanduser()
if legacy_user_dir.is_dir(): # default to standards-based location
warn('~/.thefuck is deprecated, please move ' user_dir = user_dir_modern
'config to ~/.config/thefuck')
return legacy_user_dir # for backward compatibility use legacy '~/.thefuck' if it exists
else: if user_dir_legacy.is_dir():
xdg_config_dir = os.getenv("XDG_CONFIG_HOME", "~/.config") user_dir = user_dir_legacy
return Path(xdg_config_dir).joinpath('thefuck') message = 'config path {} is deprecated. please move to {}'
warn(message.format(user_dir_legacy, user_dir_modern))
return user_dir
def _setup_user_dir(self): def _setup_user_dir(self):
"""Returns user config dir, create it when it doesn't exist.""" """Returns user config dir, create it when it doesn't exist."""