1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 02:01:13 +00:00

Merge pull request #362 from nvbn/356-fuck-endpoint

#356 fuck endpoint
This commit is contained in:
Vladimir Iakovlev 2015-09-06 13:43:24 +03:00
commit 191a2e588d
9 changed files with 88 additions and 9 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, u"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

@ -53,7 +53,7 @@ def get_aliases(mocker):
@pytest.mark.usefixtures('no_memoize', 'get_aliases')
def test_get_all_callables():
def test_get_all_executables():
all_callables = get_all_executables()
assert 'vim' in all_callables
assert 'fsck' in all_callables

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

View File

@ -10,6 +10,7 @@ import pickle
import re
from pathlib import Path
import pkg_resources
import six
@ -94,11 +95,17 @@ def get_all_executables():
return fallback
tf_alias = thefuck_alias()
return [exe.name
tf_entry_points = pkg_resources.require('thefuck')[0]\
.get_entry_map()\
.get('console_scripts', {})\
.keys()
bins = [exe.name
for path in os.environ.get('PATH', '').split(':')
for exe in _safe(lambda: list(Path(path).iterdir()), [])
if not _safe(exe.is_dir, True)] + [
alias for alias in get_aliases() if alias != tf_alias]
if not _safe(exe.is_dir, True)
and exe.name not in tf_entry_points]
aliases = [alias for alias in get_aliases() if alias != tf_alias]
return bins + aliases
def replace_argument(script, from_, to):