def get_new_command(command): old_command = command.script_parts[0] # One from history: already_used = get_closest(old_command, _get_used_executables(command), fallback_to_first=False) if already_used: new_cmds = [already_used] else: new_cmds = [] # Other from all executables: new_cmds += [ cmd for cmd in get_close_matches(old_command, get_all_executables()) if cmd not in new_cmds ] return [ ' '.join([new_command] + command.script_parts[1:]) for new_command in new_cmds ]
def test_get_all_executables(): all_callables = get_all_executables() assert 'vim' in all_callables assert 'fsck' in all_callables assert 'frick' not in all_callables
def test_get_all_executables_pathsep(path, pathsep): with patch('thefrick.utils.Path') as Path_mock: get_all_executables() Path_mock.assert_has_calls([call(p) for p in path.split(pathsep)], True)
def match(command): return (not which(command.script_parts[0]) and ('not found' in command.output or 'is not recognized as' in command.output) and bool( get_close_matches(command.script_parts[0], get_all_executables())))
def _get_executable(script_part): for executable in get_all_executables(): if script_part.startswith(executable): return executable
def match(command): return (not command.script_parts[0] in get_all_executables() and _get_executable(command.script_parts[0]))