From 12f8d017b9bb1c02cfd4d4a221924ad04569f781 Mon Sep 17 00:00:00 2001 From: mcarton Date: Thu, 9 Jul 2015 17:24:45 +0200 Subject: [PATCH 1/4] Add systemd's kind of error for the sudo rule A complete error would be: ``` % systemctl daemon-reload ==== AUTHENTICATING FOR org.freedesktop.systemd1.reload-daemon === Authentication is required to reload the systemd state. Authenticating as: martin Password: ``` --- thefuck/rules/sudo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/thefuck/rules/sudo.py b/thefuck/rules/sudo.py index 1a87ffec..31687549 100644 --- a/thefuck/rules/sudo.py +++ b/thefuck/rules/sudo.py @@ -13,7 +13,8 @@ patterns = ['permission denied', 'must be root', 'need to be root', 'need root', - 'only root can do that'] + 'only root can do that', + 'authentication is required'] def match(command, settings): From 5693bd49f76e94b9b9128910629aad2474ec3800 Mon Sep 17 00:00:00 2001 From: mcarton Date: Thu, 9 Jul 2015 18:00:59 +0200 Subject: [PATCH 2/4] #281 Add the mercurial rule to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2dc629c6..9668a63d 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `ls_lah` – adds -lah to ls; * `man` – change manual section; * `man_no_space` – fixes man commands without spaces, for example `mandiff`; +* `mercurial` – fixes wrong `hg` commands; * `mkdir_p` – adds `-p` when you trying to create directory without parent; * `no_command` – fixes wrong console commands, for example `vom/vim`; * `no_such_file` – creates missing directories with `mv` and `cp` commands; From 0b5a7a8e2daaa1418445f69e4d4c1645b3b42c16 Mon Sep 17 00:00:00 2001 From: mcarton Date: Thu, 9 Jul 2015 18:35:33 +0200 Subject: [PATCH 3/4] Fix rule name in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9668a63d..d2f8084d 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `python_execute` – appends missing `.py` when executing Python files; * `quotation_marks` – fixes uneven usage of `'` and `"` when containing args' * `rm_dir` – adds `-rf` when you trying to remove directory; -* `sed` – adds missing '/' to `sed`'s `s` commands; +* `sed_unterminated_s` – adds missing '/' to `sed`'s `s` commands; * `sl_ls` – changes `sl` to `ls`; * `ssh_known_hosts` – removes host from `known_hosts` on warning; * `sudo` – prepends `sudo` to previous command if it failed because of permissions; From 370c58e67989ee55b910f1aad470afa3c35ec025 Mon Sep 17 00:00:00 2001 From: mcarton Date: Fri, 10 Jul 2015 09:49:49 +0200 Subject: [PATCH 4/4] 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)