Ejemplo n.º 1
0
 def got_output(text, returncode):
     if text is not None:
         view.append_message(html_string(text, pre=True))
     if returncode:
         if is_ag_installed(ag_path):
             if returncode == 1:
                 message = "no match for pattern: {}".format(pattern)
             else:
                 message = "exit code: {}".format(returncode)
         else:
             message = markdown(AG_NOT_INSTALLED.format(ag_path))
         view.append_message(message, msg_type=const.ERROR)
     if returncode is not None:
         view.process_completed()
Ejemplo n.º 2
0
def github_url(editor, args):
    """Get GitHub URL"""
    if not args:
        from editxt.commands import show_command_bar
        return show_command_bar(editor, "github-url ")
    if not (editor and editor.file_path):
        raise CommandError("cannot get github URL without path")
    info = get_git_info(editor)
    if not args.remote:
        if info.remotes:
            remote = info.remotes[0]
        else:
            raise CommandError("cannot get github URL without remote name")
    else:
        remote = {r.name: r for r in info.remotes}.get(args.remote)
    if remote is None:
        raise CommandError("unknown remote: {}".format(args.remote))
    if args.rev == "HEAD":
        rev = rev_parse(info.git_dir, "--abbrev-ref")
        if rev == "HEAD":
            rev = rev_parse(info.git_dir)
    else:
        rev = args.rev
    lines = get_selected_lines(editor)
    if lines:
        if ":" in lines:
            lines = lines.replace(":", "-L")
        lines = "#L" + lines
    link = "https://github.com/{user}/{repo}/blob/{rev}/{path}{line}".format(
        user=remote.user,
        repo=remote.repo,
        rev=rev,
        path=git_relative_path(editor.file_path, info),
        line=lines,
    )
    editor.message(html_string("<a href='{0}'>{0}</a>".format(link)))