1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00

#356 Print useful information when fuck called and alias isn't configured

This commit is contained in:
nvbn 2015-09-06 13:29:42 +03:00
parent f7ce0fda25
commit 4392872568
7 changed files with 77 additions and 5 deletions

View File

@ -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']})

View File

@ -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"])

View File

@ -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)

View File

@ -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)

View File

@ -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')

View File

@ -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',

View File

@ -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()