1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-18 20:11:17 +00:00

Merge pull request #478 from MattKotsenas/feature/powershell-shell

Add Powershell as shell
This commit is contained in:
Vladimir Iakovlev 2016-03-19 02:45:26 +02:00
commit 3a39deb485
4 changed files with 61 additions and 7 deletions

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
import pytest
from thefuck.shells import Powershell
@pytest.mark.usefixtures('isfile', 'no_memoize', 'no_cache')
class TestPowershell(object):
@pytest.fixture
def shell(self):
return Powershell()
def test_and_(self, shell):
assert shell.and_('ls', 'cd') == '(ls) -and (cd)'
def test_app_alias(self, shell):
assert 'function fuck' in shell.app_alias('fuck')
assert 'function FUCK' in shell.app_alias('FUCK')
assert 'thefuck' in shell.app_alias('fuck')

View File

@ -9,20 +9,37 @@ from .fish import Fish
from .generic import Generic
from .tcsh import Tcsh
from .zsh import Zsh
from .powershell import Powershell
shells = {'bash': Bash,
'fish': Fish,
'zsh': Zsh,
'csh': Tcsh,
'tcsh': Tcsh}
'tcsh': Tcsh,
'powershell': Powershell}
def _get_shell():
try:
shell_name = Process(os.getpid()).parent().name()
except TypeError:
shell_name = Process(os.getpid()).parent.name
return shells.get(shell_name, Generic)()
proc = Process(os.getpid())
while (proc is not None):
name = None
try:
name = proc.name()
except TypeError:
name = proc.name
name = os.path.splitext(name)[0]
if name in shells:
return shells[name]()
try:
proc = proc.parent()
except TypeError:
proc = proc.parent
return Generic()
shell = _get_shell()

View File

@ -0,0 +1,18 @@
from .generic import Generic
class Powershell(Generic):
def app_alias(self, fuck):
return 'function ' + fuck + ' { \n' \
' $fuck = $(thefuck (Get-History -Count 1).CommandLine)\n' \
' if (-not [string]::IsNullOrWhiteSpace($fuck)) {\n' \
' if ($fuck.StartsWith("echo")) { $fuck = $fuck.Substring(5) }\n' \
' else { iex "$fuck" }\n' \
' }\n' \
'}\n'
def and_(self, *commands):
return u' -and '.join('({0})'.format(c) for c in commands)
def how_to_configure(self):
return 'iex "thefuck --alias"', '$profile'

View File

@ -16,7 +16,7 @@ def get_key():
ch = msvcrt.getch() # second call returns the actual key code
if ch == b'\x03':
raise const.KEY_CTRL_C
return const.KEY_CTRL_C
if ch == b'H':
return const.KEY_UP
if ch == b'P':