Create thefuck.archlinux
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
""" This file provide some utility functions for Arch Linux specific rules."""
|
||||
import thefuck.utils
|
||||
import subprocess
|
||||
|
||||
|
||||
@thefuck.utils.memoize
|
||||
def get_pkgfile(command):
|
||||
""" Gets the packages that provide the given command using `pkgfile`.
|
||||
|
||||
If the command is of the form `sudo foo`, searches for the `foo` command
|
||||
instead.
|
||||
"""
|
||||
try:
|
||||
command = command.script.strip()
|
||||
|
||||
if command.startswith('sudo '):
|
||||
command = command[5:]
|
||||
|
||||
command = command.split(" ")[0]
|
||||
|
||||
packages = subprocess.check_output(
|
||||
['pkgfile', '-b', '-v', command],
|
||||
universal_newlines=True, stderr=thefuck.utils.DEVNULL
|
||||
).splitlines()
|
||||
|
||||
return [package.split()[0] for package in packages]
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
||||
|
||||
def archlinux_env():
|
||||
if thefuck.utils.which('yaourt'):
|
||||
pacman = 'yaourt'
|
||||
elif thefuck.utils.which('pacman'):
|
||||
pacman = 'sudo pacman'
|
||||
else:
|
||||
return False, None
|
||||
|
||||
enabled_by_default = thefuck.utils.which('pkgfile')
|
||||
|
||||
return enabled_by_default, pacman
|
||||
+4
-34
@@ -1,46 +1,16 @@
|
||||
import subprocess
|
||||
from thefuck.utils import DEVNULL, which
|
||||
from thefuck.archlinux import archlinux_env, get_pkgfile
|
||||
from thefuck import shells
|
||||
from thefuck.utils import memoize
|
||||
|
||||
|
||||
@memoize
|
||||
def __get_pkgfile(command):
|
||||
try:
|
||||
command = command.script
|
||||
|
||||
if command.startswith('sudo'):
|
||||
command = command[5:]
|
||||
|
||||
command = command.split(" ")[0]
|
||||
|
||||
packages = subprocess.check_output(
|
||||
['pkgfile', '-b', '-v', command],
|
||||
universal_newlines=True, stderr=DEVNULL
|
||||
).splitlines()
|
||||
|
||||
return [package.split()[0] for package in packages]
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
return 'not found' in command.stderr and __get_pkgfile(command)
|
||||
return 'not found' in command.stderr and get_pkgfile(command)
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
packages = __get_pkgfile(command)
|
||||
packages = get_pkgfile(command)
|
||||
|
||||
formatme = shells.and_('{} -S {}', '{}')
|
||||
return [formatme.format(pacman, package, command.script)
|
||||
for package in packages]
|
||||
|
||||
|
||||
if not which('pkgfile'):
|
||||
enabled_by_default = False
|
||||
elif which('yaourt'):
|
||||
pacman = 'yaourt'
|
||||
elif which('pacman'):
|
||||
pacman = 'sudo pacman'
|
||||
else:
|
||||
enabled_by_default = False
|
||||
enabled_by_default, pacman = archlinux_env()
|
||||
|
||||
+1
-1
@@ -1,3 +1,4 @@
|
||||
from .types import Command
|
||||
from difflib import get_close_matches
|
||||
from functools import wraps
|
||||
from pathlib import Path
|
||||
@@ -6,7 +7,6 @@ import os
|
||||
import pickle
|
||||
import re
|
||||
import six
|
||||
from .types import Command
|
||||
|
||||
|
||||
DEVNULL = open(os.devnull, 'w')
|
||||
|
||||
Reference in New Issue
Block a user