1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-19 00:58:56 +00:00

#N/A: show shell information on thefuck --version

This commit is contained in:
Pablo S. Blum de Aguiar 2018-09-25 22:30:44 +02:00 committed by Pablo Santiago Blum de Aguiar
parent e7d508a9af
commit 318ae0b55c
10 changed files with 51 additions and 11 deletions

View File

@ -6,11 +6,8 @@ update The Fuck and see if the bug is still there. -->
if not, just open an issue on [GitHub](https://github.com/nvbn/thefuck) with if not, just open an issue on [GitHub](https://github.com/nvbn/thefuck) with
the following basic information: --> the following basic information: -->
The output of `thefuck --version` (something like `The Fuck 3.1 using Python 3.5.0`): The output of `thefuck --version` (something like `The Fuck 3.1 using Python
3.5.0 and Bash 4.4.12(1)-release`):
FILL THIS IN
Your shell and its version (`bash`, `zsh`, *Windows PowerShell*, etc.):
FILL THIS IN FILL THIS IN

View File

@ -73,3 +73,8 @@ class TestBash(object):
config_exists): config_exists):
config_exists.return_value = False config_exists.return_value = False
assert not shell.how_to_configure().can_configure_automatically assert not shell.how_to_configure().can_configure_automatically
def test_info(self, shell, mocker):
patch = mocker.patch('thefuck.shells.bash.Popen')
patch.return_value.stdout.read.side_effect = [b'3.5.9']
assert shell.info() == 'Bash 3.5.9'

View File

@ -112,3 +112,7 @@ class TestFish(object):
config_exists): config_exists):
config_exists.return_value = False config_exists.return_value = False
assert not shell.how_to_configure().can_configure_automatically assert not shell.how_to_configure().can_configure_automatically
def test_info(self, shell, Popen):
Popen.return_value.stdout.read.side_effect = [b'3.5.9']
assert shell.info() == 'Fish Shell 3.5.9'

View File

@ -68,3 +68,8 @@ class TestZsh(object):
config_exists): config_exists):
config_exists.return_value = False config_exists.return_value = False
assert not shell.how_to_configure().can_configure_automatically assert not shell.how_to_configure().can_configure_automatically
def test_info(self, shell, mocker):
patch = mocker.patch('thefuck.shells.zsh.Popen')
patch.return_value.stdout.read.side_effect = [b'3.5.9']
assert shell.info() == 'ZSH 3.5.9'

View File

@ -8,6 +8,7 @@ import sys # noqa: E402
from .. import logs # noqa: E402 from .. import logs # noqa: E402
from ..argument_parser import Parser # noqa: E402 from ..argument_parser import Parser # noqa: E402
from ..utils import get_installation_info # noqa: E402 from ..utils import get_installation_info # noqa: E402
from ..shells import shell # noqa: E402
from .alias import print_alias # noqa: E402 from .alias import print_alias # noqa: E402
from .fix_command import fix_command # noqa: E402 from .fix_command import fix_command # noqa: E402
@ -20,7 +21,7 @@ def main():
parser.print_help() parser.print_help()
elif known_args.version: elif known_args.version:
logs.version(get_installation_info().version, logs.version(get_installation_info().version,
sys.version.split()[0]) sys.version.split()[0], shell.info())
elif known_args.command or 'TF_HISTORY' in os.environ: elif known_args.command or 'TF_HISTORY' in os.environ:
fix_command(known_args) fix_command(known_args)
elif known_args.alias: elif known_args.alias:

View File

@ -134,7 +134,8 @@ def configured_successfully(configuration_details):
reload=configuration_details.reload)) reload=configuration_details.reload))
def version(thefuck_version, python_version): def version(thefuck_version, python_version, shell_info):
sys.stderr.write( sys.stderr.write(
u'The Fuck {} using Python {}\n'.format(thefuck_version, u'The Fuck {} using Python {} and {}\n'.format(thefuck_version,
python_version)) python_version,
shell_info))

View File

@ -1,9 +1,10 @@
import os import os
from subprocess import Popen, PIPE
from tempfile import gettempdir from tempfile import gettempdir
from uuid import uuid4 from uuid import uuid4
from ..conf import settings from ..conf import settings
from ..const import ARGUMENT_PLACEHOLDER, USER_COMMAND_MARK from ..const import ARGUMENT_PLACEHOLDER, USER_COMMAND_MARK
from ..utils import memoize from ..utils import DEVNULL, memoize
from .generic import Generic from .generic import Generic
@ -81,3 +82,10 @@ class Bash(Generic):
content=u'eval $(thefuck --alias)', content=u'eval $(thefuck --alias)',
path=config, path=config,
reload=u'source {}'.format(config)) reload=u'source {}'.format(config))
def info(self):
"""Returns the name and version of the current shell"""
proc = Popen(['bash', '-c', 'echo $BASH_VERSION'],
stdout=PIPE, stderr=DEVNULL)
version = proc.stdout.read().decode('utf-8').strip()
return u'Bash {}'.format(version)

View File

@ -103,6 +103,13 @@ class Fish(Generic):
path='~/.config/fish/config.fish', path='~/.config/fish/config.fish',
reload='fish') reload='fish')
def info(self):
"""Returns the name and version of the current shell"""
proc = Popen(['fish', '-c', 'echo $FISH_VERSION'],
stdout=PIPE, stderr=DEVNULL)
version = proc.stdout.read().decode('utf-8').strip()
return u'Fish Shell {}'.format(version)
def put_to_history(self, command): def put_to_history(self, command):
try: try:
return self._put_to_history(command) return self._put_to_history(command)

View File

@ -131,6 +131,10 @@ class Generic(object):
'type', 'typeset', 'ulimit', 'umask', 'unalias', 'unset', 'type', 'typeset', 'ulimit', 'umask', 'unalias', 'unset',
'until', 'wait', 'while'] 'until', 'wait', 'while']
def info(self):
"""Returns the name and version of the current shell"""
return 'Generic Shell'
def _create_shell_configuration(self, content, path, reload): def _create_shell_configuration(self, content, path, reload):
return ShellConfiguration( return ShellConfiguration(
content=content, content=content,

View File

@ -1,10 +1,11 @@
from time import time from time import time
import os import os
from subprocess import Popen, PIPE
from tempfile import gettempdir from tempfile import gettempdir
from uuid import uuid4 from uuid import uuid4
from ..conf import settings from ..conf import settings
from ..const import ARGUMENT_PLACEHOLDER, USER_COMMAND_MARK from ..const import ARGUMENT_PLACEHOLDER, USER_COMMAND_MARK
from ..utils import memoize from ..utils import DEVNULL, memoize
from .generic import Generic from .generic import Generic
@ -85,3 +86,10 @@ class Zsh(Generic):
content=u'eval $(thefuck --alias)', content=u'eval $(thefuck --alias)',
path='~/.zshrc', path='~/.zshrc',
reload='source ~/.zshrc') reload='source ~/.zshrc')
def info(self):
"""Returns the name and version of the current shell"""
proc = Popen(['zsh', '-c', 'echo $ZSH_VERSION'],
stdout=PIPE, stderr=DEVNULL)
version = proc.stdout.read().decode('utf-8').strip()
return u'ZSH {}'.format(version)