From 370c58e67989ee55b910f1aad470afa3c35ec025 Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 10 Jul 2015 09:49:49 +0200 Subject: [PATCH] Use `get_closest` in the tmux rule --- tests/rules/test_tmux.py | 2 +- thefuck/rules/tmux.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/rules/test_tmux.py b/tests/rules/test_tmux.py index 22111a70..ebbe6736 100644 --- a/tests/rules/test_tmux.py +++ b/tests/rules/test_tmux.py @@ -16,4 +16,4 @@ def test_match(tmux_ambiguous): def test_get_new_command(tmux_ambiguous): assert get_new_command(Command('tmux list', stderr=tmux_ambiguous), None)\ - == 'tmux list-buffers' + == 'tmux list-keys' diff --git a/thefuck/rules/tmux.py b/thefuck/rules/tmux.py index 2fa2552a..683ee46e 100644 --- a/thefuck/rules/tmux.py +++ b/thefuck/rules/tmux.py @@ -1,3 +1,4 @@ +from thefuck.utils import get_closest import re @@ -8,7 +9,12 @@ def match(command, settings): def get_new_command(command, settings): - cmd = re.match(r"ambiguous command: (.*), could be: ([^, \n]*)", + cmd = re.match(r"ambiguous command: (.*), could be: (.*)", command.stderr) - return command.script.replace(cmd.group(1), cmd.group(2)) + old_cmd = cmd.group(1) + suggestions = [cmd.strip() for cmd in cmd.group(2).split(',')] + + new_cmd = get_closest(old_cmd, suggestions) + + return command.script.replace(old_cmd, new_cmd)