From 5dbbb3b1ed9b3eb7ac7ec3eb155f7ded3b6f348e Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Mon, 3 Oct 2016 03:54:13 -0400 Subject: [PATCH 1/3] Add `... --help` to `man` suggestions This is along the lines of what @waldyrious suggested in https://github.com/nvbn/thefuck/issues/546, but it just adds a new suggestion rather than replacing the other ones. --- tests/rules/test_man.py | 2 +- thefuck/rules/man.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/rules/test_man.py b/tests/rules/test_man.py index 01eab173..1c9095ca 100644 --- a/tests/rules/test_man.py +++ b/tests/rules/test_man.py @@ -23,7 +23,7 @@ def test_not_match(command): @pytest.mark.parametrize('command, new_command', [ - (Command('man read'), ['man 3 read', 'man 2 read']), + (Command('man read'), ['man 3 read', 'man 2 read', 'read --help']), (Command('man 2 read'), 'man 3 read'), (Command('man 3 read'), 'man 2 read'), (Command('man -s2 read'), 'man -s3 read'), diff --git a/thefuck/rules/man.py b/thefuck/rules/man.py index ead1361b..6fcea5af 100644 --- a/thefuck/rules/man.py +++ b/thefuck/rules/man.py @@ -18,4 +18,10 @@ def get_new_command(command): split_cmd2.insert(1, ' 2 ') split_cmd3.insert(1, ' 3 ') - return ["".join(split_cmd3), "".join(split_cmd2)] + last_arg = command.script_parts[-1] + + return [ + "".join(split_cmd3), + "".join(split_cmd2), + last_arg + ' --help', + ] From 8bd6c5da67e55c64257345efa4e3cc454c42475c Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Mon, 3 Oct 2016 11:54:29 -0400 Subject: [PATCH 2/3] For `man foo`, try `foo --help` before `man 3 foo` `man` without a section searches all sections, so having `foo --help` suggested first makes more sense than adding a specific section. See https://github.com/nvbn/thefuck/pull/562#issuecomment-251142710 However, in cases where multiple sections have man pages for `foo`, running `man foo` could bring up the "wrong" section of man pages. `man read` is an example of this, but that should probably be handled in a way that still suggests `foo --help` first when there are *no* man pages for `foo` in any section. Closes https://github.com/nvbn/thefuck/issues/546 --- tests/rules/test_man.py | 2 +- thefuck/rules/man.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rules/test_man.py b/tests/rules/test_man.py index 1c9095ca..b51b1165 100644 --- a/tests/rules/test_man.py +++ b/tests/rules/test_man.py @@ -23,7 +23,7 @@ def test_not_match(command): @pytest.mark.parametrize('command, new_command', [ - (Command('man read'), ['man 3 read', 'man 2 read', 'read --help']), + (Command('man read'), ['read --help', 'man 3 read', 'man 2 read']), (Command('man 2 read'), 'man 3 read'), (Command('man 3 read'), 'man 2 read'), (Command('man -s2 read'), 'man -s3 read'), diff --git a/thefuck/rules/man.py b/thefuck/rules/man.py index 6fcea5af..3d0347a8 100644 --- a/thefuck/rules/man.py +++ b/thefuck/rules/man.py @@ -21,7 +21,7 @@ def get_new_command(command): last_arg = command.script_parts[-1] return [ + last_arg + ' --help', "".join(split_cmd3), "".join(split_cmd2), - last_arg + ' --help', ] From 0c84eefa55fc1b4bc4940b41d74568884344e35c Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Mon, 3 Oct 2016 13:13:35 -0400 Subject: [PATCH 3/3] Don't suggest `man 2/3 foo` if no man pages exist Suggest `foo --help` instead. However, if there are man pages, suggest `foo --help` after `man 2/3 foo` This addresses the comment in the previous commit message: > However, in cases where multiple sections have man pages for `foo`, > running `man foo` could bring up the "wrong" section of man pages. > `man read` is an example of this, but that should probably be handled in > a way that still suggests `foo --help` first when there are *no* man > pages for `foo` in any section. --- tests/rules/test_man.py | 3 ++- thefuck/rules/man.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/rules/test_man.py b/tests/rules/test_man.py index b51b1165..c4714881 100644 --- a/tests/rules/test_man.py +++ b/tests/rules/test_man.py @@ -23,7 +23,8 @@ def test_not_match(command): @pytest.mark.parametrize('command, new_command', [ - (Command('man read'), ['read --help', 'man 3 read', 'man 2 read']), + (Command('man read'), ['man 3 read', 'man 2 read', 'read --help']), + (Command('man missing', stderr="No manual entry for missing\n"), ['missing --help']), (Command('man 2 read'), 'man 3 read'), (Command('man 3 read'), 'man 2 read'), (Command('man -s2 read'), 'man -s3 read'), diff --git a/thefuck/rules/man.py b/thefuck/rules/man.py index 3d0347a8..e4ec54d9 100644 --- a/thefuck/rules/man.py +++ b/thefuck/rules/man.py @@ -12,16 +12,22 @@ def get_new_command(command): if '2' in command.script: return command.script.replace("2", "3") + last_arg = command.script_parts[-1] + help_command = last_arg + ' --help' + + # If there are no man pages for last_arg, suggest `last_arg --help` instead. + # Otherwise, suggest `--help` after suggesting other man page sections. + if command.stderr.strip() == 'No manual entry for ' + last_arg: + return [help_command] + split_cmd2 = command.script_parts split_cmd3 = split_cmd2[:] split_cmd2.insert(1, ' 2 ') split_cmd3.insert(1, ' 3 ') - last_arg = command.script_parts[-1] - return [ - last_arg + ' --help', "".join(split_cmd3), "".join(split_cmd2), + help_command, ]