Skip to content

Commit 05f6aa5

Browse files
support nixos command-not-found, closes #912
1 parent 59dc6cb commit 05f6aa5

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ The following rules are enabled by default on specific platforms only:
316316
* `brew_unknown_command` – fixes wrong brew commands, for example `brew docto/brew doctor`;
317317
* `brew_update_formula` &ndash; turns `brew update <formula>` into `brew upgrade <formula>`;
318318
* `dnf_no_such_command` &ndash; fixes mistyped DNF commands;
319+
* `nixos_cmd_not_found` &ndash; installs apps on NixOS;
319320
* `pacman` &ndash; installs app with `pacman` if it is not installed (uses `yay` or `yaourt` if available);
320321
* `pacman_not_found` &ndash; fixes package name with `pacman`, `yay` or `yaourt`.
321322

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
from thefuck.rules.nixos_cmd_not_found import match, get_new_command
3+
from thefuck.types import Command
4+
5+
6+
@pytest.mark.parametrize('command', [
7+
Command('vim', 'nix-env -iA nixos.vim')])
8+
def test_match(mocker, command):
9+
mocker.patch('thefuck.rules.nixos_cmd_not_found', return_value=None)
10+
assert match(command)
11+
12+
13+
@pytest.mark.parametrize('command', [
14+
Command('vim', ''),
15+
Command('', '')])
16+
def test_not_match(mocker, command):
17+
mocker.patch('thefuck.rules.nixos_cmd_not_found', return_value=None)
18+
assert not match(command)
19+
20+
21+
@pytest.mark.parametrize('command, new_command', [
22+
(Command('vim', 'nix-env -iA nixos.vim'), 'nix-env -iA nixos.vim && vim'),
23+
(Command('pacman', 'nix-env -iA nixos.pacman'), 'nix-env -iA nixos.pacman && pacman')])
24+
def test_get_new_command(mocker, command, new_command):
25+
assert get_new_command(command) == new_command
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import re
2+
from thefuck.specific.nix import nix_available
3+
from thefuck.shells import shell
4+
5+
regex = re.compile(r'nix-env -iA ([^\s]*)')
6+
enabled_by_default = nix_available
7+
8+
9+
def match(command):
10+
return regex.findall(command.output)
11+
12+
13+
def get_new_command(command):
14+
name = regex.findall(command.output)[0]
15+
return shell.and_('nix-env -iA {}'.format(name), command.script)

thefuck/specific/nix.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from thefuck.utils import which
2+
3+
nix_available = bool(which('nix'))

0 commit comments

Comments
 (0)