mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
Merge branch 'xdg' of https://github.com/mcarton/thefuck into mcarton-xdg
This commit is contained in:
commit
bbfedb861f
@ -225,7 +225,7 @@ Bundled, but not enabled by default:
|
|||||||
## Creating your own rules
|
## Creating your own rules
|
||||||
|
|
||||||
For adding your own rule you should create `your-rule-name.py`
|
For adding your own rule you should create `your-rule-name.py`
|
||||||
in `~/.thefuck/rules`. The rule should contain two functions:
|
in `~/.config/thefuck/rules`. The rule should contain two functions:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
match(command: Command) -> bool
|
match(command: Command) -> bool
|
||||||
@ -242,7 +242,7 @@ and optional `enabled_by_default`, `requires_output` and `priority` variables.
|
|||||||
`Command` has three attributes: `script`, `stdout` and `stderr`.
|
`Command` has three attributes: `script`, `stdout` and `stderr`.
|
||||||
|
|
||||||
*Rules api changed in 3.0:* For accessing settings in rule you need to import it with `from thefuck.conf import settings`.
|
*Rules api changed in 3.0:* For accessing settings in rule you need to import it with `from thefuck.conf import settings`.
|
||||||
`settings` is a special object filled with `~/.thefuck/settings.py` and values from env ([see more below](#settings)).
|
`settings` is a special object filled with `~/.config/thefuck/settings.py` and values from env ([see more below](#settings)).
|
||||||
|
|
||||||
Simple example of the rule for running script with `sudo`:
|
Simple example of the rule for running script with `sudo`:
|
||||||
|
|
||||||
@ -272,7 +272,7 @@ requires_output = True
|
|||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
|
||||||
The Fuck has a few settings parameters which can be changed in `~/.thefuck/settings.py`:
|
The Fuck has a few settings parameters which can be changed in `$XDG_CONFIG_HOME/thefuck/settings.py` (`$XDG_CONFIG_HOME` defaults to `~/.config`):
|
||||||
|
|
||||||
* `rules` – list of enabled rules, by default `thefuck.conf.DEFAULT_RULES`;
|
* `rules` – list of enabled rules, by default `thefuck.conf.DEFAULT_RULES`;
|
||||||
* `exclude_rules` – list of disabled rules, by default `[]`;
|
* `exclude_rules` – list of disabled rules, by default `[]`;
|
||||||
|
@ -26,7 +26,7 @@ ENV_TO_ATTR = {'THEFUCK_RULES': 'rules',
|
|||||||
'THEFUCK_PRIORITY': 'priority',
|
'THEFUCK_PRIORITY': 'priority',
|
||||||
'THEFUCK_DEBUG': 'debug'}
|
'THEFUCK_DEBUG': 'debug'}
|
||||||
|
|
||||||
SETTINGS_HEADER = u"""# ~/.thefuck/settings.py: The Fuck settings file
|
SETTINGS_HEADER = u"""# The Fuck settings file
|
||||||
#
|
#
|
||||||
# The rules are defined as in the example bellow:
|
# The rules are defined as in the example bellow:
|
||||||
#
|
#
|
||||||
@ -73,7 +73,15 @@ class Settings(dict):
|
|||||||
|
|
||||||
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."""
|
||||||
|
|
||||||
|
# for backward compatibility, use `~/.thefuck` if it exists
|
||||||
user_dir = Path(os.path.expanduser('~/.thefuck'))
|
user_dir = Path(os.path.expanduser('~/.thefuck'))
|
||||||
|
|
||||||
|
if not user_dir.is_dir():
|
||||||
|
default_xdg_config_dir = os.path.expanduser("~/.config")
|
||||||
|
xdg_config_dir = os.getenv("XDG_CONFIG_HOME", default_xdg_config_dir)
|
||||||
|
user_dir = Path(os.path.join(xdg_config_dir, 'thefuck'))
|
||||||
|
|
||||||
rules_dir = user_dir.joinpath('rules')
|
rules_dir = user_dir.joinpath('rules')
|
||||||
if not rules_dir.is_dir():
|
if not rules_dir.is_dir():
|
||||||
rules_dir.mkdir(parents=True)
|
rules_dir.mkdir(parents=True)
|
||||||
|
@ -185,7 +185,18 @@ def cache(*depends_on):
|
|||||||
if cache.disabled:
|
if cache.disabled:
|
||||||
return fn(*args, **kwargs)
|
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
|
# A bit obscure, but simplest way to generate unique key for
|
||||||
# functions and methods in python 2 and 3:
|
# functions and methods in python 2 and 3:
|
||||||
key = '{}.{}'.format(fn.__module__, repr(fn).split('at')[0])
|
key = '{}.{}'.format(fn.__module__, repr(fn).split('at')[0])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user