#611: Allow to configure alias automatically by calling fuck twice

This commit is contained in:
Vladimir Iakovlev
2017-03-13 21:50:13 +01:00
parent 2379573cf2
commit 14a9cd85aa
19 changed files with 336 additions and 54 deletions
+17 -16
View File
@@ -178,6 +178,21 @@ def for_app(*app_names, **kwargs):
return decorator(_for_app)
def get_cache_dir():
default_xdg_cache_dir = os.path.expanduser("~/.cache")
cache_dir = os.getenv("XDG_CACHE_HOME", default_xdg_cache_dir)
# 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
return cache_dir
def cache(*depends_on):
"""Caches function result in temporary file.
@@ -194,21 +209,6 @@ def cache(*depends_on):
except OSError:
return '0'
def _get_cache_path():
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
return cache_path
@decorator
def _cache(fn, *args, **kwargs):
if cache.disabled:
@@ -219,7 +219,8 @@ def cache(*depends_on):
key = '{}.{}'.format(fn.__module__, repr(fn).split('at')[0])
etag = '.'.join(_get_mtime(name) for name in depends_on)
cache_path = _get_cache_path()
cache_dir = get_cache_dir()
cache_path = Path(cache_dir).joinpath('thefuck').as_posix()
try:
with closing(shelve.open(cache_path)) as db: