mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-01 08:18:34 +00:00
Follow the XDG Base Directory Specification
This commit is contained in:
parent
3da26192cb
commit
4a48108c69
@ -224,7 +224,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
|
||||||
@ -241,7 +241,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`:
|
||||||
|
|
||||||
@ -271,7 +271,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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user