mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
#165 fix python 2 support
This commit is contained in:
parent
608d48e408
commit
5864faadef
@ -1,14 +1,15 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
from thefuck.utils import DEVNULL
|
||||||
|
|
||||||
|
|
||||||
def __command_available(command):
|
def __command_available(command):
|
||||||
try:
|
try:
|
||||||
subprocess.check_output([command], stderr=subprocess.DEVNULL)
|
subprocess.check_output([command], stderr=DEVNULL)
|
||||||
return True
|
return True
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
# command exists but is not happy to be called without any argument
|
# command exists but is not happy to be called without any argument
|
||||||
return True
|
return True
|
||||||
except FileNotFoundError:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,9 +8,7 @@ from subprocess import Popen, PIPE
|
|||||||
from time import time
|
from time import time
|
||||||
import os
|
import os
|
||||||
from psutil import Process
|
from psutil import Process
|
||||||
|
from .utils import DEVNULL
|
||||||
|
|
||||||
FNULL = open(os.devnull, 'w')
|
|
||||||
|
|
||||||
|
|
||||||
class Generic(object):
|
class Generic(object):
|
||||||
@ -58,7 +56,7 @@ class Bash(Generic):
|
|||||||
return name, value
|
return name, value
|
||||||
|
|
||||||
def _get_aliases(self):
|
def _get_aliases(self):
|
||||||
proc = Popen('bash -ic alias', stdout=PIPE, stderr=FNULL, shell=True)
|
proc = Popen('bash -ic alias', stdout=PIPE, stderr=DEVNULL, shell=True)
|
||||||
return dict(
|
return dict(
|
||||||
self._parse_alias(alias)
|
self._parse_alias(alias)
|
||||||
for alias in proc.stdout.read().decode('utf-8').split('\n')
|
for alias in proc.stdout.read().decode('utf-8').split('\n')
|
||||||
@ -80,7 +78,7 @@ class Zsh(Generic):
|
|||||||
return name, value
|
return name, value
|
||||||
|
|
||||||
def _get_aliases(self):
|
def _get_aliases(self):
|
||||||
proc = Popen('zsh -ic alias', stdout=PIPE, stderr=FNULL, shell=True)
|
proc = Popen('zsh -ic alias', stdout=PIPE, stderr=DEVNULL, shell=True)
|
||||||
return dict(
|
return dict(
|
||||||
self._parse_alias(alias)
|
self._parse_alias(alias)
|
||||||
for alias in proc.stdout.read().decode('utf-8').split('\n')
|
for alias in proc.stdout.read().decode('utf-8').split('\n')
|
||||||
|
@ -4,6 +4,9 @@ import six
|
|||||||
from .types import Command
|
from .types import Command
|
||||||
|
|
||||||
|
|
||||||
|
DEVNULL = open(os.devnull, 'w')
|
||||||
|
|
||||||
|
|
||||||
def which(program):
|
def which(program):
|
||||||
"""Returns `program` path or `None`."""
|
"""Returns `program` path or `None`."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user