mirror of
https://github.com/nvbn/thefuck.git
synced 2025-11-02 16:12:08 +00:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce922758a4 | ||
|
|
c47968a180 | ||
|
|
581c97ec4b | ||
|
|
0a53966f9b | ||
|
|
ed4e7946d7 | ||
|
|
2ed96b1d51 | ||
|
|
79d94e2651 | ||
|
|
c08182509d | ||
|
|
1d2d907c60 | ||
|
|
13996261be | ||
|
|
afcd7fc67e | ||
|
|
c0c7397057 | ||
|
|
707743e7a7 | ||
|
|
d8779dc4a6 | ||
|
|
ba9214f7fc | ||
|
|
660422806c | ||
|
|
3c8978784b | ||
|
|
995b373347 | ||
|
|
dbe1a94c7d | ||
|
|
15e13d7c1a | ||
|
|
3194913965 | ||
|
|
237f43ebdb | ||
|
|
a5aadc6e90 | ||
|
|
18ce062300 | ||
|
|
73bc6c0184 | ||
|
|
0296a4a46d | ||
|
|
54a9769c10 | ||
|
|
abc7238d14 | ||
|
|
710a72ee8c | ||
|
|
e09c6530e5 | ||
|
|
b1da6a883a | ||
|
|
a9e3b22fa4 | ||
|
|
9debcdf676 | ||
|
|
718cadb85a | ||
|
|
910e6f4759 | ||
|
|
d3146aa0ac | ||
|
|
190e47ecdb | ||
|
|
84a28d8c73 | ||
|
|
551e35e3b6 | ||
|
|
2bebfabf8d | ||
|
|
675317b247 | ||
|
|
6cf430cc23 | ||
|
|
7e55041963 | ||
|
|
fc364b99b9 | ||
|
|
742f6f9c94 | ||
|
|
cd1bee9cb0 |
@@ -132,6 +132,7 @@ thefuck-alias >> ~/.bashrc
|
||||
[Or in your shell config (Bash, Zsh, Fish, Powershell).](https://github.com/nvbn/thefuck/wiki/Shell-aliases)
|
||||
|
||||
Changes will be available only in a new shell session.
|
||||
To make them available immediately, run `source ~/.bashrc` (or your shell config file like `.zshrc`).
|
||||
|
||||
|
||||
## Update
|
||||
@@ -155,12 +156,17 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
||||
* `django_south_ghost` – adds `--delete-ghost-migrations` to failed because ghosts django south migration;
|
||||
* `django_south_merge` – adds `--merge` to inconsistent django south migration;
|
||||
* `fix_alt_space` – replaces Alt+Space with Space character;
|
||||
* `javac` – appends missing `.java` when compiling Java files;
|
||||
* `java` – removes `.java` extension when running Java programs;
|
||||
* `git_add` – fix *"Did you forget to 'git add'?"*;
|
||||
* `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch;
|
||||
* `git_checkout` – creates the branch before checking-out;
|
||||
* `git_diff_staged` – adds `--staged` to previous `git diff` with unexpected output;
|
||||
* `git_no_command` – fixes wrong git commands like `git brnch`;
|
||||
* `git_pull` – sets upstream before executing previous `git pull`;
|
||||
* `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`;
|
||||
* `git_stash` – stashes you local modifications before rebasing or switching branch;
|
||||
* `go_run` – appends `.go` extension when compiling/running Go programs
|
||||
* `grep_recursive` – adds `-r` when you trying to grep directory;
|
||||
* `has_exists_script` – prepends `./` when script/binary exists;
|
||||
* `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`;
|
||||
@@ -170,8 +176,10 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
||||
* `mkdir_p` – adds `-p` when you trying to create directory without parent;
|
||||
* `no_command` – fixes wrong console commands, for example `vom/vim`;
|
||||
* `no_such_file` – creates missing directories with `mv` and `cp` commands;
|
||||
* `open` – prepends `http` to address passed to `open`;
|
||||
* `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;
|
||||
* `quotation_marks` – fixes uneven usage of `'` and `"` when containing args'
|
||||
* `rm_dir` – adds `-rf` when you trying to remove directory;
|
||||
* `sl_ls` – changes `sl` to `ls`;
|
||||
* `ssh_known_hosts` – removes host from `known_hosts` on warning;
|
||||
@@ -184,6 +192,7 @@ Enabled by default only on specific platforms:
|
||||
* `apt_get` – installs app from apt if it not installed;
|
||||
* `brew_install` – fixes formula name for `brew install`;
|
||||
* `brew_unknown_command` – fixes wrong brew commands, for example `brew docto/brew doctor`;
|
||||
* `brew_upgrade` – appends `--all` to `brew upgrade` as per Homebrew's new behaviour
|
||||
* `pacman` – installs app with `pacman` or `yaourt` if it is not installed.
|
||||
|
||||
Bundled, but not enabled by default:
|
||||
|
||||
2
setup.py
2
setup.py
@@ -1,7 +1,7 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
VERSION = '1.43'
|
||||
VERSION = '1.45'
|
||||
|
||||
|
||||
setup(name='thefuck',
|
||||
|
||||
15
tests/rules/test_brew_upgrade.py
Normal file
15
tests/rules/test_brew_upgrade.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pytest
|
||||
from thefuck.rules.brew_upgrade import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='brew upgrade')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('brew upgrade'), 'brew upgrade --all')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command, None) == new_command
|
||||
18
tests/rules/test_git_branch_list.py
Normal file
18
tests/rules/test_git_branch_list.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from thefuck import shells
|
||||
from thefuck.rules.git_branch_list import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
def test_match():
|
||||
assert match(Command('git branch list'), None)
|
||||
|
||||
|
||||
def test_not_match():
|
||||
assert not match(Command(), None)
|
||||
assert not match(Command('git commit'), None)
|
||||
assert not match(Command('git branch'), None)
|
||||
assert not match(Command('git stash list'), None)
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
assert (get_new_command(Command('git branch list'), None) ==
|
||||
shells.and_('git branch --delete list', 'git branch'))
|
||||
27
tests/rules/test_git_diff_staged.py
Normal file
27
tests/rules/test_git_diff_staged.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
from thefuck.rules.git_diff_staged import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='git diff'),
|
||||
Command(script='git df'),
|
||||
Command(script='git ds')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='git tag'),
|
||||
Command(script='git branch'),
|
||||
Command(script='git log')])
|
||||
def test_not_match(command):
|
||||
assert not match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('git diff'), 'git diff --staged'),
|
||||
(Command('git df'), 'git df --staged'),
|
||||
(Command('git ds'), 'git ds --staged')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command, None) == new_command
|
||||
17
tests/rules/test_go_run.py
Normal file
17
tests/rules/test_go_run.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import pytest
|
||||
from thefuck.rules.go_run import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='go run foo'),
|
||||
Command(script='go run bar')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('go run foo'), 'go run foo.go'),
|
||||
(Command('go run bar'), 'go run bar.go')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command, None) == new_command
|
||||
17
tests/rules/test_java.py
Normal file
17
tests/rules/test_java.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import pytest
|
||||
from thefuck.rules.java import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='java foo.java'),
|
||||
Command(script='java bar.java')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('java foo.java'), 'java foo'),
|
||||
(Command('java bar.java'), 'java bar')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command, None) == new_command
|
||||
17
tests/rules/test_javac.py
Normal file
17
tests/rules/test_javac.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import pytest
|
||||
from thefuck.rules.javac import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='javac foo'),
|
||||
Command(script='javac bar')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('javac foo'), 'javac foo.java'),
|
||||
(Command('javac bar'), 'javac bar.java')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command, None) == new_command
|
||||
@@ -2,6 +2,7 @@ import pytest
|
||||
from thefuck.rules.man import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('man read'),
|
||||
Command('man 2 read'),
|
||||
@@ -14,6 +15,13 @@ def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('man'),
|
||||
Command('man ')])
|
||||
def test_not_match(command):
|
||||
assert not match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('man read'), 'man 3 read'),
|
||||
(Command('man 2 read'), 'man 3 read'),
|
||||
|
||||
25
tests/rules/test_open.py
Normal file
25
tests/rules/test_open.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
from thefuck.rules.open import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='open foo.com'),
|
||||
Command(script='open foo.ly'),
|
||||
Command(script='open foo.org'),
|
||||
Command(script='open foo.net'),
|
||||
Command(script='open foo.se'),
|
||||
Command(script='open foo.io')])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('open foo.com'), 'open http://foo.com'),
|
||||
(Command('open foo.ly'), 'open http://foo.ly'),
|
||||
(Command('open foo.org'), 'open http://foo.org'),
|
||||
(Command('open foo.net'), 'open http://foo.net'),
|
||||
(Command('open foo.se'), 'open http://foo.se'),
|
||||
(Command('open foo.io'), 'open http://foo.io')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command, None) == new_command
|
||||
19
tests/rules/test_quotation_marks.py
Normal file
19
tests/rules/test_quotation_marks.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import pytest
|
||||
from thefuck.rules.quotation_marks import match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script="git commit -m \'My Message\""),
|
||||
Command(script="git commit -am \"Mismatched Quotation Marks\'"),
|
||||
Command(script="echo \"hello\'")])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command("git commit -m \'My Message\""), "git commit -m \"My Message\""),
|
||||
(Command("git commit -am \"Mismatched Quotation Marks\'"), "git commit -am \"Mismatched Quotation Marks\""),
|
||||
(Command("echo \"hello\'"), "echo \"hello\"")])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command, None) == new_command
|
||||
@@ -78,9 +78,22 @@ class TestFish(object):
|
||||
def shell(self):
|
||||
return shells.Fish()
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def Popen(self, mocker):
|
||||
mock = mocker.patch('thefuck.shells.Popen')
|
||||
mock.return_value.stdout.read.return_value = (
|
||||
b'fish_config\nfuck\nfunced\nfuncsave\ngrep\nhistory\nll\nmath')
|
||||
return mock
|
||||
|
||||
@pytest.mark.parametrize('before, after', [
|
||||
('pwd', 'pwd'),
|
||||
('ll', 'll')]) # Fish has no aliases but functions
|
||||
('fuck', 'fish -ic "fuck"'),
|
||||
('find', 'find'),
|
||||
('funced', 'fish -ic "funced"'),
|
||||
('awk', 'awk'),
|
||||
('math "2 + 2"', r'fish -ic "math \"2 + 2\""'),
|
||||
('vim', 'vim'),
|
||||
('ll', 'fish -ic "ll"')]) # Fish has no aliases but functions
|
||||
def test_from_shell(self, before, after, shell):
|
||||
assert shell.from_shell(before) == after
|
||||
|
||||
@@ -98,7 +111,14 @@ class TestFish(object):
|
||||
assert shell.and_('foo', 'bar') == 'foo; and bar'
|
||||
|
||||
def test_get_aliases(self, shell):
|
||||
assert shell.get_aliases() == {}
|
||||
assert shell.get_aliases() == {'fish_config': 'fish_config',
|
||||
'fuck': 'fuck',
|
||||
'funced': 'funced',
|
||||
'funcsave': 'funcsave',
|
||||
'grep': 'grep',
|
||||
'history': 'history',
|
||||
'll': 'll',
|
||||
'math': 'math'}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('isfile')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
from mock import Mock
|
||||
from thefuck.utils import sudo_support, wrap_settings
|
||||
from thefuck.utils import sudo_support, wrap_settings, memoize
|
||||
from thefuck.types import Settings
|
||||
from tests.utils import Command
|
||||
|
||||
@@ -24,3 +24,11 @@ def test_sudo_support(return_value, command, called, result):
|
||||
fn = Mock(return_value=return_value, __name__='')
|
||||
assert sudo_support(fn)(Command(command), None) == result
|
||||
fn.assert_called_once_with(Command(called), None)
|
||||
|
||||
|
||||
def test_memoize():
|
||||
fn = Mock(__name__='fn')
|
||||
memoized = memoize(fn)
|
||||
memoized()
|
||||
memoized()
|
||||
fn.assert_called_once_with()
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from thefuck import shells
|
||||
from thefuck.utils import sudo_support
|
||||
|
||||
try:
|
||||
import CommandNotFound
|
||||
except ImportError:
|
||||
enabled_by_default = False
|
||||
|
||||
|
||||
@sudo_support
|
||||
def match(command, settings):
|
||||
if 'not found' in command.stderr:
|
||||
try:
|
||||
@@ -17,7 +18,7 @@ def match(command, settings):
|
||||
# IndexError is thrown when no matching package is found
|
||||
return False
|
||||
|
||||
|
||||
@sudo_support
|
||||
def get_new_command(command, settings):
|
||||
c = CommandNotFound.CommandNotFound()
|
||||
pkgs = c.getPackages(command.script.split(" ")[0])
|
||||
|
||||
14
thefuck/rules/brew_upgrade.py
Normal file
14
thefuck/rules/brew_upgrade.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Appends --all to the brew upgrade command
|
||||
#
|
||||
# Example:
|
||||
# > brew upgrade
|
||||
# Warning: brew upgrade with no arguments will change behaviour soon!
|
||||
# It currently upgrades all formula but this will soon change to require '--all'.
|
||||
#
|
||||
#
|
||||
|
||||
def match(command, settings):
|
||||
return (command.script == 'brew upgrade')
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return command.script + ' --all'
|
||||
@@ -47,7 +47,7 @@ def get_new_command(command, settings):
|
||||
cwd = os.path.join(cwd, best_matches[0])
|
||||
else:
|
||||
return cd_mkdir.get_new_command(command, settings)
|
||||
return "cd {0}".format(cwd)
|
||||
return 'cd "{0}"'.format(cwd)
|
||||
|
||||
|
||||
enabled_by_default = True
|
||||
|
||||
10
thefuck/rules/git_branch_list.py
Normal file
10
thefuck/rules/git_branch_list.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from thefuck import shells
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
# catches "git branch list" in place of "git branch"
|
||||
return command.script.split() == 'git branch list'.split()
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return shells.and_('git branch --delete list', 'git branch')
|
||||
6
thefuck/rules/git_diff_staged.py
Normal file
6
thefuck/rules/git_diff_staged.py
Normal file
@@ -0,0 +1,6 @@
|
||||
def match(command, settings):
|
||||
return command.script.startswith('git d')
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return '{} --staged'.format(command.script)
|
||||
14
thefuck/rules/go_run.py
Normal file
14
thefuck/rules/go_run.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Appends .go when compiling go files
|
||||
#
|
||||
# Example:
|
||||
# > go run foo
|
||||
# error: go run: no go files listed
|
||||
#
|
||||
#
|
||||
|
||||
def match(command, settings):
|
||||
return (command.script.startswith ('go run ')
|
||||
and not command.script.endswith('.go'))
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return command.script + '.go'
|
||||
13
thefuck/rules/java.py
Normal file
13
thefuck/rules/java.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Fixes common java command mistake
|
||||
#
|
||||
# Example:
|
||||
# > java foo.java
|
||||
# Error: Could not find or load main class foo.java
|
||||
#
|
||||
|
||||
def match(command, settings):
|
||||
return (command.script.startswith ('java ')
|
||||
and command.script.endswith ('.java'))
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return command.script[:-5]
|
||||
15
thefuck/rules/javac.py
Normal file
15
thefuck/rules/javac.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Appends .java when compiling java files
|
||||
#
|
||||
# Example:
|
||||
# > javac foo
|
||||
# error: Class names, 'foo', are only accepted if annotation
|
||||
# processing is explicitly requested
|
||||
#
|
||||
#
|
||||
|
||||
def match(command, settings):
|
||||
return (command.script.startswith ('javac ')
|
||||
and not command.script.endswith('.java'))
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return command.script + '.java'
|
||||
@@ -1,5 +1,5 @@
|
||||
def match(command, settings):
|
||||
return command.script.startswith('man')
|
||||
return command.script.strip().startswith('man ')
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
|
||||
24
thefuck/rules/open.py
Normal file
24
thefuck/rules/open.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Opens URL's in the default web browser
|
||||
#
|
||||
# Example:
|
||||
# > open github.com
|
||||
# The file ~/github.com does not exist.
|
||||
# Perhaps you meant 'http://github.com'?
|
||||
#
|
||||
#
|
||||
|
||||
def match(command, settings):
|
||||
return (command.script.startswith ('open')
|
||||
and (
|
||||
# Wanted to use this:
|
||||
# 'http' in command.stderr
|
||||
'.com' in command.script
|
||||
or '.net' in command.script
|
||||
or '.org' in command.script
|
||||
or '.ly' in command.script
|
||||
or '.io' in command.script
|
||||
or '.se' in command.script
|
||||
or '.edu' in command.script))
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return 'open http://' + command.script[5:]
|
||||
14
thefuck/rules/quotation_marks.py
Normal file
14
thefuck/rules/quotation_marks.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Fixes careless " and ' usage
|
||||
#
|
||||
# Example:
|
||||
# > git commit -m 'My Message"
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
def match(command, settings):
|
||||
return ('\'' in command.script
|
||||
and '\"' in command.script)
|
||||
|
||||
def get_new_command(command, settings):
|
||||
return command.script.replace ('\'', '\"')
|
||||
@@ -11,7 +11,8 @@ patterns = ['permission denied',
|
||||
'requested operation requires superuser privilege',
|
||||
'must be run as root',
|
||||
'must be superuser',
|
||||
'Need to be root']
|
||||
'Need to be root',
|
||||
'you must be root to run this program.']
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
|
||||
@@ -8,10 +8,11 @@ from subprocess import Popen, PIPE
|
||||
from time import time
|
||||
import os
|
||||
from psutil import Process
|
||||
from .utils import DEVNULL
|
||||
from .utils import DEVNULL, memoize
|
||||
|
||||
|
||||
class Generic(object):
|
||||
|
||||
def get_aliases(self):
|
||||
return {}
|
||||
|
||||
@@ -61,8 +62,10 @@ class Bash(Generic):
|
||||
value = value[1:-1]
|
||||
return name, value
|
||||
|
||||
@memoize
|
||||
def get_aliases(self):
|
||||
proc = Popen('bash -ic alias', stdout=PIPE, stderr=DEVNULL, shell=True)
|
||||
proc = Popen('bash -ic alias', stdout=PIPE, stderr=DEVNULL,
|
||||
shell=True)
|
||||
return dict(
|
||||
self._parse_alias(alias)
|
||||
for alias in proc.stdout.read().decode('utf-8').split('\n')
|
||||
@@ -91,6 +94,25 @@ class Fish(Generic):
|
||||
" end\n"
|
||||
"end")
|
||||
|
||||
@memoize
|
||||
def get_aliases(self):
|
||||
proc = Popen('fish -ic functions', stdout=PIPE, stderr=DEVNULL,
|
||||
shell=True)
|
||||
functions = proc.stdout.read().decode('utf-8').strip().split('\n')
|
||||
return {function: function for function in functions}
|
||||
|
||||
def _expand_aliases(self, command_script):
|
||||
aliases = self.get_aliases()
|
||||
binary = command_script.split(' ')[0]
|
||||
if binary in aliases:
|
||||
return 'fish -ic "{}"'.format(command_script.replace('"', r'\"'))
|
||||
else:
|
||||
return command_script
|
||||
|
||||
def from_shell(self, command_script):
|
||||
"""Prepares command before running in app."""
|
||||
return self._expand_aliases(command_script)
|
||||
|
||||
def _get_history_file_name(self):
|
||||
return os.path.expanduser('~/.config/fish/fish_history')
|
||||
|
||||
@@ -111,8 +133,10 @@ class Zsh(Generic):
|
||||
value = value[1:-1]
|
||||
return name, value
|
||||
|
||||
@memoize
|
||||
def get_aliases(self):
|
||||
proc = Popen('zsh -ic alias', stdout=PIPE, stderr=DEVNULL, shell=True)
|
||||
proc = Popen('zsh -ic alias', stdout=PIPE, stderr=DEVNULL,
|
||||
shell=True)
|
||||
return dict(
|
||||
self._parse_alias(alias)
|
||||
for alias in proc.stdout.read().decode('utf-8').split('\n')
|
||||
@@ -134,8 +158,10 @@ class Tcsh(Generic):
|
||||
name, value = alias.split("\t", 1)
|
||||
return name, value
|
||||
|
||||
@memoize
|
||||
def get_aliases(self):
|
||||
proc = Popen('tcsh -ic alias', stdout=PIPE, stderr=DEVNULL, shell=True)
|
||||
proc = Popen('tcsh -ic alias', stdout=PIPE, stderr=DEVNULL,
|
||||
shell=True)
|
||||
return dict(
|
||||
self._parse_alias(alias)
|
||||
for alias in proc.stdout.read().decode('utf-8').split('\n')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from functools import wraps
|
||||
import os
|
||||
import pickle
|
||||
import six
|
||||
from .types import Command
|
||||
|
||||
@@ -62,3 +63,18 @@ def sudo_support(fn):
|
||||
else:
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
|
||||
def memoize(fn):
|
||||
"""Caches previous calls to the function."""
|
||||
memo = {}
|
||||
|
||||
@wraps(fn)
|
||||
def wrapper(*args, **kwargs):
|
||||
key = pickle.dumps((args, kwargs))
|
||||
if key not in memo:
|
||||
memo[key] = fn(*args, **kwargs)
|
||||
|
||||
return memo[key]
|
||||
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user