#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
+16
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')
+12
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',
+24
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()