mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-15 15:18:53 +00:00
- remove deprecated distutils.spawn import - add shutil import - implement find_executable using shutil.which for better compatibility
62 lines
1.1 KiB
Python
62 lines
1.1 KiB
Python
import os
|
|
import sys
|
|
import tty
|
|
import termios
|
|
import colorama
|
|
# from distutils.spawn import find_executable
|
|
from .. import const
|
|
import shutil
|
|
|
|
def find_executable(name):
|
|
return shutil.which(name)
|
|
|
|
init_output = colorama.init
|
|
|
|
|
|
def getch():
|
|
fd = sys.stdin.fileno()
|
|
old = termios.tcgetattr(fd)
|
|
try:
|
|
tty.setraw(fd)
|
|
return sys.stdin.read(1)
|
|
finally:
|
|
termios.tcsetattr(fd, termios.TCSADRAIN, old)
|
|
|
|
|
|
def get_key():
|
|
ch = getch()
|
|
|
|
if ch in const.KEY_MAPPING:
|
|
return const.KEY_MAPPING[ch]
|
|
elif ch == '\x1b':
|
|
next_ch = getch()
|
|
if next_ch == '[':
|
|
last_ch = getch()
|
|
|
|
if last_ch == 'A':
|
|
return const.KEY_UP
|
|
elif last_ch == 'B':
|
|
return const.KEY_DOWN
|
|
|
|
return ch
|
|
|
|
|
|
def open_command(arg):
|
|
if find_executable('xdg-open'):
|
|
return 'xdg-open ' + arg
|
|
return 'open ' + arg
|
|
|
|
|
|
try:
|
|
from pathlib import Path
|
|
except ImportError:
|
|
from pathlib2 import Path
|
|
|
|
|
|
def _expanduser(self):
|
|
return self.__class__(os.path.expanduser(str(self)))
|
|
|
|
|
|
if not hasattr(Path, 'expanduser'):
|
|
Path.expanduser = _expanduser
|