diff --git a/git-open b/git-open index 1683aacba58ee80989a504155bf1e05594fd1e23..22c21ad278a7dbca21f98cfdcf13aecbe8e159b9 100755 --- a/git-open +++ b/git-open @@ -17,7 +17,8 @@ def gitconf(field): return popen("git config " + field) def remote_url(remote_name): - return gitconf("remote.{}.url".format(remote_name)) + # return gitconf("remote.{}.url".format(remote_name)) + return popen(f'git remote get-url {remote_name}').strip() def to_http(url): if url[0:4] == "http": @@ -25,7 +26,8 @@ def to_http(url): if url[0:4] == "git@": base, path = url[4:].split(":") return "https://" + base + "/" + path - return "http://www.nicememe.website" + raise Exception("URL doesn't start with either 'http' or 'git@'") + # return "http://www.nicememe.website" def xdg_open(item): subprocess.run(["xdg-open", item]) @@ -34,10 +36,10 @@ def err(s): print("\x1b[0;31mError\x1b[m " + s) def warn(s): - print("\x1b[0;32mWarn\x1b[m " + s) + print("\x1b[0;33mWarn\x1b[m " + s) def info(s): - print("\x1b[0;33mInfo\x1b[m " + s) + print("\x1b[0;32mInfo\x1b[m " + s) def main(args): out = popen("git remote") @@ -49,23 +51,17 @@ def main(args): if not remotes: err("No remotes") - if len(remotes) == 1: - if remote and remotes[0] != remote: - err("No remote with name " + remote) - return - xdg_open(to_http(remote_url(remotes[0]))) + for remote in remotes: + try: + url = to_http(remote_url(remote)) + xdg_open(url) + info(f'opening {url}') + break + except Exception as e: + warn(str(e)) else: - if remote: - if remote in remotes: - xdg_open(to_http(remote_url(remote))) - return - else: - err("No remote with name " + remote) - return - - info("Multiple remotes found, defaulting to " + remotes[0]) - xdg_open(to_http(remote_url(remotes[0]))) + err("All remotes failed") if __name__ == "__main__": main(sys.argv)