diff --git a/setup.py b/setup.py index d20ba4dc..4464fa7d 100755 --- a/setup.py +++ b/setup.py @@ -41,4 +41,5 @@ setup(name='thefuck', extras_require=extras_require, entry_points={'console_scripts': [ 'thefuck = thefuck.main:main', - 'thefuck-alias = thefuck.main:print_alias']}) + 'thefuck-alias = thefuck.main:print_alias', + 'fuck = thefuck.main:how_to_configure_alias']}) diff --git a/tests/functional/plots.py b/tests/functional/plots.py index 1b4d06aa..910b4b2b 100644 --- a/tests/functional/plots.py +++ b/tests/functional/plots.py @@ -78,3 +78,9 @@ def without_confirmation(proc, TIMEOUT): proc.sendline(u'fuck') assert proc.expect([TIMEOUT, u'echo test']) assert proc.expect([TIMEOUT, u'test']) + + +def how_to_configure(proc, TIMEOUT): + proc.sendline(u'unalias fuck') + proc.sendline(u'fuck') + assert proc.expect([TIMEOUT, "alias isn't configured"]) diff --git a/tests/functional/test_bash.py b/tests/functional/test_bash.py index a8b69ffe..26d3e7d4 100644 --- a/tests/functional/test_bash.py +++ b/tests/functional/test_bash.py @@ -1,7 +1,7 @@ import pytest from tests.functional.plots import with_confirmation, without_confirmation, \ refuse_with_confirmation, history_changed, history_not_changed, \ - select_command_with_arrows + select_command_with_arrows, how_to_configure containers = ((u'thefuck/ubuntu-python3-bash', u'''FROM ubuntu:latest @@ -55,3 +55,9 @@ def test_refuse_with_confirmation(proc, TIMEOUT): def test_without_confirmation(proc, TIMEOUT): without_confirmation(proc, TIMEOUT) history_changed(proc, TIMEOUT, u'echo test') + + +@pytest.mark.functional +@pytest.mark.once_without_docker +def test_how_to_configure_alias(proc, TIMEOUT): + how_to_configure(proc, TIMEOUT) diff --git a/tests/functional/test_zsh.py b/tests/functional/test_zsh.py index 1bcb77fb..c0df1f09 100644 --- a/tests/functional/test_zsh.py +++ b/tests/functional/test_zsh.py @@ -1,8 +1,9 @@ import pytest from tests.functional.plots import with_confirmation, without_confirmation, \ - refuse_with_confirmation, history_changed, history_not_changed, select_command_with_arrows + refuse_with_confirmation, history_changed, history_not_changed, \ + select_command_with_arrows, how_to_configure -containers = (('ubuntu-python3-zsh', +containers = (('thefuck/ubuntu-python3-zsh', u'''FROM ubuntu:latest RUN apt-get update RUN apt-get install -yy python3 python3-pip python3-dev git @@ -10,7 +11,7 @@ containers = (('ubuntu-python3-zsh', RUN ln -s /usr/bin/pip3 /usr/bin/pip RUN apt-get install -yy zsh''', u'zsh'), - ('ubuntu-python2-zsh', + ('thefuck/ubuntu-python2-zsh', u'''FROM ubuntu:latest RUN apt-get update RUN apt-get install -yy python python-pip python-dev git @@ -59,3 +60,9 @@ def test_refuse_with_confirmation(proc, TIMEOUT): def test_without_confirmation(proc, TIMEOUT): without_confirmation(proc, TIMEOUT) history_changed(proc, TIMEOUT, u'echo test') + + +@pytest.mark.functional +@pytest.mark.once_without_docker +def test_how_to_configure_alias(proc, TIMEOUT): + how_to_configure(proc, TIMEOUT) diff --git a/thefuck/logs.py b/thefuck/logs.py index ae5f1ad2..4db63486 100644 --- a/thefuck/logs.py +++ b/thefuck/logs.py @@ -76,3 +76,19 @@ def debug_time(msg, settings): yield finally: debug(u'{} took: {}'.format(msg, datetime.now() - started), settings) + + +def how_to_configure_alias(configuration_details, settings): + print("Seems like {bold}fuck{reset} alias isn't configured!".format( + bold=color(colorama.Style.BRIGHT, settings), + reset=color(colorama.Style.RESET_ALL, settings))) + if configuration_details: + content, path = configuration_details + print( + "Please put {bold}{content}{reset} in your " + "{bold}{path}{reset}.".format( + bold=color(colorama.Style.BRIGHT, settings), + reset=color(colorama.Style.RESET_ALL, settings), + path=path, + content=content)) + print('More details - https://github.com/nvbn/thefuck#manual-installation') diff --git a/thefuck/main.py b/thefuck/main.py index 94aaef5b..046973a1 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -120,6 +120,18 @@ def print_alias(entry_point=True): print(shells.app_alias(alias)) +def how_to_configure_alias(): + """Shows useful information about how-to configure alias. + + It'll be only visible when user type fuck and when alias isn't configured. + + """ + colorama.init() + user_dir = setup_user_dir() + settings = conf.get_settings(user_dir) + logs.how_to_configure_alias(shells.how_to_configure(), settings) + + def main(): parser = ArgumentParser(prog='thefuck') parser.add_argument('-v', '--version', diff --git a/thefuck/shells.py b/thefuck/shells.py index 753373fa..9634f1d7 100644 --- a/thefuck/shells.py +++ b/thefuck/shells.py @@ -72,6 +72,9 @@ class Generic(object): def and_(self, *commands): return u' && '.join(commands) + def how_to_configure(self): + return + class Bash(Generic): def app_alias(self, fuck): @@ -103,6 +106,15 @@ class Bash(Generic): def _script_from_history(self, line): return line + def how_to_configure(self): + if os.path.join(os.path.expanduser('~'), '.bashrc'): + config = '~/.bashrc' + elif os.path.join(os.path.expanduser('~'), '.bash_profile'): + config = '~/.bashrc' + else: + config = 'bash config' + return 'eval $(thefuck --alias)', config + class Fish(Generic): @@ -156,6 +168,9 @@ class Fish(Generic): def and_(self, *commands): return u'; and '.join(commands) + def how_to_configure(self): + return 'eval thefuck --alias', '~/.config/fish/config.fish' + class Zsh(Generic): def app_alias(self, fuck): @@ -191,6 +206,9 @@ class Zsh(Generic): else: return '' + def how_to_configure(self): + return 'eval $(thefuck --alias)', '~/.zshrc' + class Tcsh(Generic): def app_alias(self, fuck): @@ -217,6 +235,9 @@ class Tcsh(Generic): def _get_history_line(self, command_script): return u'#+{}\n{}\n'.format(int(time()), command_script) + def how_to_configure(self): + return 'eval `thefuck --alias`', '~/.tcshrc' + shells = defaultdict(Generic, { 'bash': Bash(), @@ -266,3 +287,6 @@ def get_aliases(): @memoize def get_history(): return list(_get_shell().get_history()) + +def how_to_configure(): + return _get_shell().how_to_configure()