From 8f25c95f06f03b75ddca190141b2a630e1a2b811 Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 16 Oct 2015 17:33:52 +0200 Subject: [PATCH] Use XDG_CACHE_HOME for cache --- thefuck/utils.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/thefuck/utils.py b/thefuck/utils.py index 06ec934..fba72a3 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -185,7 +185,18 @@ def cache(*depends_on): if cache.disabled: return fn(*args, **kwargs) - cache_path = settings.user_dir.joinpath('.thefuck-cache').as_posix() + default_xdg_cache_dir = os.path.expanduser("~/.cache") + cache_dir = os.getenv("XDG_CACHE_HOME", default_xdg_cache_dir) + cache_path = Path(cache_dir).joinpath('thefuck').as_posix() + + # Ensure the cache_path exists, Python 2 does not have the exist_ok + # parameter + try: + os.makedirs(cache_dir) + except OSError: + if not os.path.isdir(cache_dir): + raise + # A bit obscure, but simplest way to generate unique key for # functions and methods in python 2 and 3: key = '{}.{}'.format(fn.__module__, repr(fn).split('at')[0])