mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 09:39:01 +00:00
Merge 80e1e9efc911fd5ae42bd1b75502f732b859b7cd into c7e7e1d884d3bb241ea6448f72a989434c2a35ec
This commit is contained in:
commit
db27b7bf4c
@ -6,7 +6,7 @@ import six
|
|||||||
from .. import logs
|
from .. import logs
|
||||||
from ..conf import settings
|
from ..conf import settings
|
||||||
from ..const import ARGUMENT_PLACEHOLDER
|
from ..const import ARGUMENT_PLACEHOLDER
|
||||||
from ..utils import DEVNULL, cache
|
from ..utils import DEVNULL, cache, data_dir
|
||||||
from .generic import Generic
|
from .generic import Generic
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ class Fish(Generic):
|
|||||||
return command_script
|
return command_script
|
||||||
|
|
||||||
def _get_history_file_name(self):
|
def _get_history_file_name(self):
|
||||||
return os.path.expanduser('~/.config/fish/fish_history')
|
return data_dir().joinpath("fish").joinpath("fish_history")
|
||||||
|
|
||||||
def _get_history_line(self, command_script):
|
def _get_history_line(self, command_script):
|
||||||
return u'- cmd: {}\n when: {}\n'.format(command_script, int(time()))
|
return u'- cmd: {}\n when: {}\n'.format(command_script, int(time()))
|
||||||
|
@ -196,6 +196,40 @@ def for_app(*app_names, **kwargs):
|
|||||||
return decorator(_for_app)
|
return decorator(_for_app)
|
||||||
|
|
||||||
|
|
||||||
|
def _xdg_dir(env, default):
|
||||||
|
"""
|
||||||
|
Returns the XDG user directory by first checking the given environment variable
|
||||||
|
and then resulting to the default filepath.
|
||||||
|
|
||||||
|
# Note
|
||||||
|
|
||||||
|
The directory gets created if it doesn't exist.
|
||||||
|
"""
|
||||||
|
|
||||||
|
default_xdg_dir = os.path.expanduser(default)
|
||||||
|
dir = os.getenv(env, default_xdg_dir)
|
||||||
|
|
||||||
|
# Ensure the cache_path exists, Python 2 does not have the exist_ok
|
||||||
|
# parameter
|
||||||
|
try:
|
||||||
|
os.makedirs(dir)
|
||||||
|
except OSError:
|
||||||
|
if not os.path.isdir(dir):
|
||||||
|
raise
|
||||||
|
|
||||||
|
return dir
|
||||||
|
|
||||||
|
|
||||||
|
def cache_dir():
|
||||||
|
"""Returns the user's XDG cache directory."""
|
||||||
|
return Path(_xdg_dir("XDG_CACHE_HOME", "~/.cache"))
|
||||||
|
|
||||||
|
|
||||||
|
def data_dir():
|
||||||
|
"""Returns the user's XDG data directory."""
|
||||||
|
return Path(_xdg_dir("XDG_DATA_HOME", "~/.local/share"))
|
||||||
|
|
||||||
|
|
||||||
class Cache(object):
|
class Cache(object):
|
||||||
"""Lazy read cache and save changes at exit."""
|
"""Lazy read cache and save changes at exit."""
|
||||||
|
|
||||||
@ -210,8 +244,7 @@ class Cache(object):
|
|||||||
self._db = {}
|
self._db = {}
|
||||||
|
|
||||||
def _setup_db(self):
|
def _setup_db(self):
|
||||||
cache_dir = self._get_cache_dir()
|
cache_path = cache_dir().joinpath('thefuck').as_posix()
|
||||||
cache_path = Path(cache_dir).joinpath('thefuck').as_posix()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._db = shelve.open(cache_path)
|
self._db = shelve.open(cache_path)
|
||||||
@ -223,20 +256,6 @@ class Cache(object):
|
|||||||
|
|
||||||
atexit.register(self._db.close)
|
atexit.register(self._db.close)
|
||||||
|
|
||||||
def _get_cache_dir(self):
|
|
||||||
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 _get_mtime(self, path):
|
def _get_mtime(self, path):
|
||||||
try:
|
try:
|
||||||
return str(os.path.getmtime(path))
|
return str(os.path.getmtime(path))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user