def pathfind(editor, args): """Find file by path""" if args is None and editor is not None: args = Options( path_pattern=get_selection_regex(editor), search_path=base_path(editor), unrestricted=False, ) if not (args and args.path_pattern): from editxt.commands import show_command_bar return show_command_bar(editor, "pathfind ") pattern = args.path_pattern search_path = args.search_path if not search_path: return "please specify search path" ag_path = editor.app.config.for_command("ag")["path"] view = editor.get_output_view() line_proc = make_path_processor(view, pattern, ag_path, search_path, editor) command = [ ag_path, '--files-with-matches', '--file-search-regex', pattern, '.', # match every file (even empty files when unrestricted) ] if args.unrestricted: command.insert(-1, "--unrestricted") view.process = threaded_exec_shell(command, cwd=search_path, **line_proc)
def ag(editor, args): """Search for files matching pattern""" if args is None: from editxt.commands import show_command_bar show_command_bar(editor, "ag ") return elif args.pattern is None: raise CommandError("please specify a pattern to match") pattern = args.pattern if "-i" in args.options or "--ignore-case" in args.options: pattern = RegexPattern(pattern, pattern.flags | re.IGNORECASE) elif pattern.flags & re.IGNORECASE: args.options.append("--ignore-case") ag_path = editor.app.config.for_command("ag")["path"] options = editor.app.config.for_command("ag")["options"] options = DEFAULT_OPTIONS + shlex.split(options) cwd = args.path or editor.dirname() view = editor.get_output_view() line_processor = make_line_processor(view, pattern, ag_path, cwd) command = [ag_path, pattern] + [o for o in args.options if o] + options view.process = threaded_exec_shell(command, cwd=cwd, **line_processor)
def blame(editor, args): """Invoke `git gui blame` on file path Example configuration: command: blame: git_path: /opt/local/bin/git """ if not args: from editxt.commands import show_command_bar return show_command_bar(editor, "blame ") if not (args.path and isfile(args.path)): raise CommandError("cannot blame file without path") git_path = editor.app.config.for_command("blame")["git_path"] command = [git_path, "gui", "blame", args.path] output = [] def got_output(text, returncode): if returncode is None: output.append(text) else: if returncode: if git_path == "git": try: command[0] = subprocess.check_output( ["which", "git"], universal_newlines=True).strip() except subprocess.CalledProcessError: pass output.insert(0, " ".join(command) + "\n") output.append("\nexit code: {}".format(returncode)) view.append_message("".join(output), msg_type=const.ERROR) view.process_completed() view = editor.get_output_view() view.process = threaded_exec_shell( command, cwd=dirname(realpath(args.path)), got_output=got_output, kill_on_cancel=False, )