mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 06:38:32 +00:00
#441: Move function for getting current alias to utils
This commit is contained in:
parent
0b2bda9e85
commit
a2ec5aa3ff
@ -12,7 +12,7 @@ def history(mocker):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def alias(mocker):
|
def alias(mocker):
|
||||||
return mocker.patch('thefuck.rules.history.thefuck_alias',
|
return mocker.patch('thefuck.rules.history.get_alias',
|
||||||
return_value='fuck')
|
return_value='fuck')
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ from . import logs, types, shells
|
|||||||
from .conf import settings
|
from .conf import settings
|
||||||
from .corrector import get_corrected_commands
|
from .corrector import get_corrected_commands
|
||||||
from .exceptions import EmptyCommand
|
from .exceptions import EmptyCommand
|
||||||
from .utils import get_installation_info
|
from .utils import get_installation_info, get_alias
|
||||||
from .ui import select_command
|
from .ui import select_command
|
||||||
|
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ def print_alias(entry_point=True):
|
|||||||
else:
|
else:
|
||||||
position = 2
|
position = 2
|
||||||
|
|
||||||
alias = shells.thefuck_alias()
|
alias = get_alias()
|
||||||
if len(sys.argv) > position:
|
if len(sys.argv) > position:
|
||||||
alias = sys.argv[position]
|
alias = sys.argv[position]
|
||||||
print(shells.app_alias(alias))
|
print(shells.app_alias(alias))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from difflib import get_close_matches
|
from difflib import get_close_matches
|
||||||
from thefuck.shells import get_history, thefuck_alias
|
from thefuck.shells import get_history
|
||||||
from thefuck.utils import get_closest, memoize, get_all_executables
|
from thefuck.utils import get_closest, memoize, get_all_executables, get_alias
|
||||||
|
|
||||||
|
|
||||||
def _not_corrected(history, tf_alias):
|
def _not_corrected(history, tf_alias):
|
||||||
@ -17,7 +17,7 @@ def _not_corrected(history, tf_alias):
|
|||||||
@memoize
|
@memoize
|
||||||
def _history_of_exists_without_current(command):
|
def _history_of_exists_without_current(command):
|
||||||
history = get_history()
|
history = get_history()
|
||||||
tf_alias = thefuck_alias()
|
tf_alias = get_alias()
|
||||||
executables = get_all_executables()
|
executables = get_all_executables()
|
||||||
return [line for line in _not_corrected(history, tf_alias)
|
return [line for line in _not_corrected(history, tf_alias)
|
||||||
if not line.startswith(tf_alias) and not line == command.script
|
if not line.startswith(tf_alias) and not line == command.script
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
from thefuck.shells import thefuck_alias
|
from thefuck.utils import memoize, get_alias
|
||||||
from thefuck.utils import memoize
|
|
||||||
|
|
||||||
target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?'''
|
target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?'''
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ def match(command):
|
|||||||
return False
|
return False
|
||||||
matched_layout = _get_matched_layout(command)
|
matched_layout = _get_matched_layout(command)
|
||||||
return matched_layout and \
|
return matched_layout and \
|
||||||
_switch_command(command, matched_layout) != thefuck_alias()
|
_switch_command(command, matched_layout) != get_alias()
|
||||||
|
|
||||||
|
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
|
@ -42,10 +42,6 @@ def app_alias(alias):
|
|||||||
return _get_shell().app_alias(alias)
|
return _get_shell().app_alias(alias)
|
||||||
|
|
||||||
|
|
||||||
def thefuck_alias():
|
|
||||||
return os.environ.get('TF_ALIAS', 'fuck')
|
|
||||||
|
|
||||||
|
|
||||||
def put_to_history(command):
|
def put_to_history(command):
|
||||||
try:
|
try:
|
||||||
return _get_shell().put_to_history(command)
|
return _get_shell().put_to_history(command)
|
||||||
|
@ -93,7 +93,7 @@ def get_closest(word, possibilities, n=3, cutoff=0.6, fallback_to_first=True):
|
|||||||
|
|
||||||
@memoize
|
@memoize
|
||||||
def get_all_executables():
|
def get_all_executables():
|
||||||
from thefuck.shells import thefuck_alias, get_aliases
|
from thefuck.shells import get_aliases
|
||||||
|
|
||||||
def _safe(fn, fallback):
|
def _safe(fn, fallback):
|
||||||
try:
|
try:
|
||||||
@ -101,7 +101,7 @@ def get_all_executables():
|
|||||||
except OSError:
|
except OSError:
|
||||||
return fallback
|
return fallback
|
||||||
|
|
||||||
tf_alias = thefuck_alias()
|
tf_alias = get_alias()
|
||||||
tf_entry_points = get_installation_info().get_entry_map()\
|
tf_entry_points = get_installation_info().get_entry_map()\
|
||||||
.get('console_scripts', {})\
|
.get('console_scripts', {})\
|
||||||
.keys()
|
.keys()
|
||||||
@ -260,3 +260,7 @@ def compatibility_call(fn, *args):
|
|||||||
|
|
||||||
def get_installation_info():
|
def get_installation_info():
|
||||||
return pkg_resources.require('thefuck')[0]
|
return pkg_resources.require('thefuck')[0]
|
||||||
|
|
||||||
|
|
||||||
|
def get_alias():
|
||||||
|
return os.environ.get('TF_ALIAS', 'fuck')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user