From d3146aa0aca57522820f5bdb0a22f5b248de407e Mon Sep 17 00:00:00 2001 From: Cami Diez Date: Sat, 23 May 2015 23:18:15 +0800 Subject: [PATCH] Addressed Issue #210 --- tests/rules/test_open.py | 25 +++++++++++++++++++++++++ thefuck/rules/open.py | 24 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/rules/test_open.py create mode 100644 thefuck/rules/open.py diff --git a/tests/rules/test_open.py b/tests/rules/test_open.py new file mode 100644 index 00000000..ea350b55 --- /dev/null +++ b/tests/rules/test_open.py @@ -0,0 +1,25 @@ +import pytest +from thefuck.rules.open import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('command', [ + Command(script='open foo.com'), + Command(script='open foo.ly'), + Command(script='open foo.org'), + Command(script='open foo.net'), + Command(script='open foo.se'), + Command(script='open foo.io')]) +def test_match(command): + assert match(command, None) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('open foo.com'), 'open http://foo.com'), + (Command('open foo.ly'), 'open http://foo.ly'), + (Command('open foo.org'), 'open http://foo.org'), + (Command('open foo.net'), 'open http://foo.net'), + (Command('open foo.se'), 'open http://foo.se'), + (Command('open foo.io'), 'open http://foo.io')]) +def test_get_new_command(command, new_command): + assert get_new_command(command, None) == new_command diff --git a/thefuck/rules/open.py b/thefuck/rules/open.py new file mode 100644 index 00000000..c799b0a4 --- /dev/null +++ b/thefuck/rules/open.py @@ -0,0 +1,24 @@ +# Opens URL's in the default web browser +# +# Example: +# > open github.com +# The file ~/github.com does not exist. +# Perhaps you meant 'http://github.com'? +# +# + +def match(command, settings): + return (command.script.startswith ('open') + and ( + # Wanted to use this: + # 'http' in command.stderr + '.com' in command.script + or '.net' in command.script + or '.org' in command.script + or '.ly' in command.script + or '.io' in command.script + or '.se' in command.script + or '.edu' in command.script)) + +def get_new_command(command, settings): + return 'open http://' + command.script[5:]