Skip to content
Snippets Groups Projects
Commit c07d33f6 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

open: fix linter warnings.

parent 89671c1b
No related branches found
No related tags found
No related merge requests found
......@@ -40,13 +40,16 @@ def popen(str):
sys.exit(1)
return out
def gitconf(field):
return popen("git config " + field)
def remote_url(remote_name):
# return gitconf("remote.{}.url".format(remote_name))
return popen(f'git remote get-url {remote_name}').strip()
def to_http(url):
for pattern in configuration['patterns']:
if match := re.match(pattern['i'], url):
......@@ -69,23 +72,29 @@ def to_http(url):
return "https://" + base + "/" + path
raise Exception("URL doesn't start with either 'http' or 'git@'")
def xdg_open(item):
subprocess.run(["xdg-open", item])
def err(s):
print("\x1b[0;31mError\x1b[m " + s)
def warn(s):
print("\x1b[0;33mWarn\x1b[m " + s)
def info(s):
print("\x1b[0;32mInfo\x1b[m " + s)
def open_remote(remote):
url = to_http(remote_url(remote))
xdg_open(url)
info(f'opening {url}')
def main(args):
out = popen("git remote")
remotes = out.strip().split("\n")
......@@ -94,7 +103,7 @@ def main(args):
do = open_remote
if args.dry_run:
do = lambda x: print(to_http(remote_url(x)))
do = lambda x: print(to_http(remote_url(x))) # noqa: E731
if not remotes:
err("No remotes")
......@@ -117,6 +126,7 @@ def main(args):
else:
err("All remotes failed")
def load_configuration():
global configuration
# TODO possibly add ~/.config/git/open.yaml to list
......@@ -129,10 +139,12 @@ def load_configuration():
except FileNotFoundError:
pass
if __name__ == "__main__":
# Note that argparse gives `--help' and `-h', but git "eats"
# `--help'. `-h' does however work.
parser = argparse.ArgumentParser(description='open git remotes in web browser')
parser = argparse.ArgumentParser(
description='open git remotes in web browser')
parser.add_argument('-n', '--dry-run', action='store_true', dest='dry_run')
parser.add_argument('remote', action='store', nargs='?')
args = parser.parse_args()
......@@ -141,4 +153,3 @@ if __name__ == "__main__":
load_configuration()
main(args)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment