diff --git a/README.md b/README.md index 213590b4..d911a000 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,8 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `sudo` – prepends `sudo` to previous command if it failed because of permissions; * `switch_layout` – switches command from your local layout to en; * `systemctl` – correctly orders parameters of confusing systemctl; -* `test.py` &ndasg; runs `py.test` instead of `test.py`; +* `test.py` – runs `py.test` instead of `test.py`; +* `tmux` – fixes tmux commands; * `whois` – fixes `whois` command. Enabled by default only on specific platforms: diff --git a/tests/rules/test_tmux.py b/tests/rules/test_tmux.py new file mode 100644 index 00000000..22111a70 --- /dev/null +++ b/tests/rules/test_tmux.py @@ -0,0 +1,19 @@ +import pytest +from thefuck.rules.tmux import match, get_new_command +from tests.utils import Command + + +@pytest.fixture +def tmux_ambiguous(): + return "ambiguous command: list, could be: " \ + "list-buffers, list-clients, list-commands, list-keys, " \ + "list-panes, list-sessions, list-windows" + + +def test_match(tmux_ambiguous): + assert match(Command('tmux list', stderr=tmux_ambiguous), None) + + +def test_get_new_command(tmux_ambiguous): + assert get_new_command(Command('tmux list', stderr=tmux_ambiguous), None)\ + == 'tmux list-buffers' diff --git a/thefuck/rules/tmux.py b/thefuck/rules/tmux.py new file mode 100644 index 00000000..2fa2552a --- /dev/null +++ b/thefuck/rules/tmux.py @@ -0,0 +1,14 @@ +import re + + +def match(command, settings): + return ('tmux' in command.script + and 'ambiguous command:' in command.stderr + and 'could be:' in command.stderr) + + +def get_new_command(command, settings): + cmd = re.match(r"ambiguous command: (.*), could be: ([^, \n]*)", + command.stderr) + + return command.script.replace(cmd.group(1), cmd.group(2))