Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

powershell encoding warning on every 'fuck' execution #514

Closed
cuwaters opened this issue Jun 7, 2016 · 4 comments
Closed

powershell encoding warning on every 'fuck' execution #514

cuwaters opened this issue Jun 7, 2016 · 4 comments
Labels

Comments

@cuwaters
Copy link

cuwaters commented Jun 7, 2016

each time I run fuck in my powershell prompt, I get warned about mismatched stdin and stdout encodings:

c:\python34\lib\site-packages\win_unicode_console__init__.py:27: RuntimeWarning: sys.stdin.encoding == 'utf-8', whereas sys.stdout.encoding == 'cp1252', readline hook consumer may assume they are the same
readline_hook.enable(use_pyreadline=use_pyreadline)

I saw issue #486, but this issue is slightly different (the encoding isn't 'None').

@MattKotsenas
Copy link
Contributor

I see this as well. There are two options I've come up with, but I don't fully understand the ramifications of doing so. One is:

diff --git a/thefuck/system/win32.py b/thefuck/system/win32.py
index a8b6c0a..6d6fa0a 100644
--- a/thefuck/system/win32.py
+++ b/thefuck/system/win32.py
@@ -7,7 +7,7 @@ from .. import const

 def init_output():
     import colorama
-    win_unicode_console.enable()
+    win_unicode_console.enable(use_readline_hook = False)
     colorama.init()

Which works on my system (Windows 10 + PowerShell), but I don't know enough about win_unicode_console to know if it is correct.

The safer but hack-ish way is to just ignore the warning

diff --git a/thefuck/system/win32.py b/thefuck/system/win32.py
index a8b6c0a..a38c584 100644
--- a/thefuck/system/win32.py
+++ b/thefuck/system/win32.py
@@ -3,14 +3,15 @@ import sys
 import msvcrt
 import win_unicode_console
 from .. import const
+import warnings

 def init_output():
     import colorama
-    win_unicode_console.enable()
+    with warnings.catch_warnings():
+        warnings.simplefilter("ignore")
+        win_unicode_console.enable()
     colorama.init()

Let me know how I can help with a fix here as this is the last bug I run into using thefuck with PowerShell. Thanks!

@Porges
Copy link

Porges commented Mar 9, 2017

I fixed this by setting $env:PYTHONIOENCODING='utf-8' in my $PROFILE

@nvbn nvbn added the windows label Mar 14, 2017
@jagretz
Copy link

jagretz commented Jan 1, 2019

FYI, this is documented https://github.com/nvbn/thefuck/wiki/Shell-aliases#powershell so this issue can likely be closed

@lucknaumann
Copy link

@nvbn Thanks for this!
FYI - I had neglected to put the fuck alias in my PS profile which is how I found this thread but it gave me slightly wrong instructions. The "More details" link should be the one mentioned above https://github.com/nvbn/thefuck/wiki/Shell-aliases#powershell. Maybe also mentioning placing $env:PYTHONIOENCODING='utf-8' before the fuck alias would also be helpful.

Seems like fuck alias isn't configured!
Please put iex "$(thefuck --alias)" in your $profile and apply changes with . $profile or restart your shell.
More details - https://github.com/nvbn/thefuck#manual-installation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants