From 3cd187a3bb47351890ac7308464e1a2780507220 Mon Sep 17 00:00:00 2001 From: Gerardo Grignoli Date: Mon, 10 Jul 2023 10:09:27 -0300 Subject: [PATCH] #1329: Add support for Windows `CMD` and easier setup for Powershell * feat: Added nicer support for Windows CMD & Powershell * Fix typo * Fix CMD console color after thefuck Ctrl-C * Update setup.py Co-authored-by: Pablo Aguiar * Update setup.py Co-authored-by: Pablo Aguiar * Addressed PR comments * fix spacing and newline issues --------- Co-authored-by: Pablo Aguiar --- scripts/fuck.bat | 2 ++ scripts/fuck.ps1 | 22 ++++++++++++++++++++++ setup.py | 16 +++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 scripts/fuck.bat create mode 100644 scripts/fuck.ps1 diff --git a/scripts/fuck.bat b/scripts/fuck.bat new file mode 100644 index 00000000..eb6bd344 --- /dev/null +++ b/scripts/fuck.bat @@ -0,0 +1,2 @@ +@set PYTHONIOENCODING=utf-8 +@powershell -noprofile -c "cmd /c \"$(thefuck %* $(doskey /history)[-2])\"; [Console]::ResetColor();" diff --git a/scripts/fuck.ps1 b/scripts/fuck.ps1 new file mode 100644 index 00000000..ad76c3c1 --- /dev/null +++ b/scripts/fuck.ps1 @@ -0,0 +1,22 @@ +if ((Get-Command "fuck").CommandType -eq "Function") { + fuck @args; + [Console]::ResetColor() + exit +} + +"First time use of thefuck detected. " + +if ((Get-Content $PROFILE -Raw -ErrorAction Ignore) -like "*thefuck*") { +} else { + " - Adding thefuck intialization to user `$PROFILE" + $script = "`n`$env:PYTHONIOENCODING='utf-8' `niex `"`$(thefuck --alias)`""; + Write-Output $script | Add-Content $PROFILE +} + +" - Adding fuck() function to current session..." +$env:PYTHONIOENCODING='utf-8' +iex "$($(thefuck --alias).Replace("function fuck", "function global:fuck"))" + +" - Invoking fuck()`n" +fuck @args; +[Console]::ResetColor() diff --git a/setup.py b/setup.py index dab99a03..1105aef4 100755 --- a/setup.py +++ b/setup.py @@ -40,6 +40,17 @@ extras_require = {':python_version<"3.4"': ['pathlib2'], ':python_version>"2.7"': ['decorator', 'pyte'], ":sys_platform=='win32'": ['win_unicode_console']} +if sys.platform == "win32": + scripts = ['scripts\\fuck.bat', 'scripts\\fuck.ps1'] + entry_points = {'console_scripts': [ + 'thefuck = thefuck.entrypoints.main:main', + 'thefuck_firstuse = thefuck.entrypoints.not_configured:main']} +else: + scripts = [] + entry_points = {'console_scripts': [ + 'thefuck = thefuck.entrypoints.main:main', + 'fuck = thefuck.entrypoints.not_configured:main']} + setup(name='thefuck', version=VERSION, description="Magnificent app which corrects your previous console command", @@ -55,6 +66,5 @@ setup(name='thefuck', python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', install_requires=install_requires, extras_require=extras_require, - entry_points={'console_scripts': [ - 'thefuck = thefuck.entrypoints.main:main', - 'fuck = thefuck.entrypoints.not_configured:main']}) + scripts=scripts, + entry_points=entry_points)