From 1f48d5e12a4e103dfea7ce33b82ef3b25565346d Mon Sep 17 00:00:00 2001 From: mcarton Date: Wed, 20 May 2015 17:55:48 +0200 Subject: [PATCH] Add a rule to change man section --- README.md | 1 + tests/rules/test_man.py | 26 ++++++++++++++++++++++++++ thefuck/rules/man.py | 13 +++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/rules/test_man.py create mode 100644 thefuck/rules/man.py diff --git a/README.md b/README.md index a1a176ce..7b89f107 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `has_exists_script` – prepends `./` when script/binary exists; * `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`; * `ls_lah` – adds -lah to ls; +* `man` – change manual section; * `man_no_space` – fixes man commands without spaces, for example `mandiff`; * `mkdir_p` – adds `-p` when you trying to create directory without parent; * `no_command` – fixes wrong console commands, for example `vom/vim`; diff --git a/tests/rules/test_man.py b/tests/rules/test_man.py new file mode 100644 index 00000000..b2e7f281 --- /dev/null +++ b/tests/rules/test_man.py @@ -0,0 +1,26 @@ +import pytest +from thefuck.rules.man import match, get_new_command +from tests.utils import Command + +@pytest.mark.parametrize('command', [ + Command('man read'), + Command('man 2 read'), + Command('man 3 read'), + Command('man -s2 read'), + Command('man -s3 read'), + Command('man -s 2 read'), + Command('man -s 3 read')]) +def test_match(command): + assert match(command, None) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('man read'), 'man 3 read'), + (Command('man 2 read'), 'man 3 read'), + (Command('man 3 read'), 'man 2 read'), + (Command('man -s2 read'), 'man -s3 read'), + (Command('man -s3 read'), 'man -s2 read'), + (Command('man -s 2 read'), 'man -s 3 read'), + (Command('man -s 3 read'), 'man -s 2 read')]) +def test_get_new_command(command, new_command): + assert get_new_command(command, None) == new_command diff --git a/thefuck/rules/man.py b/thefuck/rules/man.py new file mode 100644 index 00000000..13ff0c6a --- /dev/null +++ b/thefuck/rules/man.py @@ -0,0 +1,13 @@ +def match(command, settings): + return command.script.startswith('man') + + +def get_new_command(command, settings): + if '3' in command.script: + return command.script.replace("3", "2") + if '2' in command.script: + return command.script.replace("2", "3") + + split_cmd = command.script.split() + split_cmd.insert(1, ' 3 ') + return "".join(split_cmd)