mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
commit
fb069b74d7
@ -151,6 +151,7 @@ using matched rule and run it. Rules enabled by default:
|
|||||||
* `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`;
|
* `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`;
|
||||||
* `mkdir_p` – adds `-p` when you trying to create directory without parent;
|
* `mkdir_p` – adds `-p` when you trying to create directory without parent;
|
||||||
* `no_command` – fixes wrong console commands, for example `vom/vim`;
|
* `no_command` – fixes wrong console commands, for example `vom/vim`;
|
||||||
|
* `pacman` – installs app with `pacman` or `yaourt` if it is not installed;
|
||||||
* `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`;
|
* `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`;
|
||||||
* `python_command` – prepends `python` when you trying to run not executable/without `./` python script;
|
* `python_command` – prepends `python` when you trying to run not executable/without `./` python script;
|
||||||
* `sl_ls` – changes `sl` to `ls`;
|
* `sl_ls` – changes `sl` to `ls`;
|
||||||
|
42
thefuck/rules/pacman.py
Normal file
42
thefuck/rules/pacman.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def __command_available(command):
|
||||||
|
try:
|
||||||
|
subprocess.check_output([command], stderr=subprocess.DEVNULL)
|
||||||
|
return True
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
# command exists but is not happy to be called without any argument
|
||||||
|
return True
|
||||||
|
except FileNotFoundError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def __get_pkgfile(command):
|
||||||
|
try:
|
||||||
|
return subprocess.check_output(
|
||||||
|
['pkgfile', '-b', '-v', command.script.split(" ")[0]],
|
||||||
|
universal_newlines=True, stderr=subprocess.DEVNULL
|
||||||
|
).split()
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def match(command, settings):
|
||||||
|
return 'not found' in command.stderr and __get_pkgfile(command)
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_command(command, settings):
|
||||||
|
package = __get_pkgfile(command)[0]
|
||||||
|
|
||||||
|
return '{} -S {} && {}'.format(pacman, package, command.script)
|
||||||
|
|
||||||
|
|
||||||
|
if not __command_available('pkgfile'):
|
||||||
|
enabled_by_default = False
|
||||||
|
elif __command_available('yaourt'):
|
||||||
|
pacman = 'yaourt'
|
||||||
|
elif __command_available('pacman'):
|
||||||
|
pacman = 'sudo pacman'
|
||||||
|
else:
|
||||||
|
enabled_by_default = False
|
Loading…
x
Reference in New Issue
Block a user