|
|
@@ -1,12 +1,18 @@
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
+from __future__ import annotations
|
|
|
+
|
|
|
import re
|
|
|
import subprocess
|
|
|
import sys
|
|
|
+import typing
|
|
|
import urllib.parse
|
|
|
|
|
|
-def oneliner(*args):
|
|
|
- return subprocess.check_output(args, universal_newlines=True).strip()
|
|
|
+if typing.TYPE_CHECKING:
|
|
|
+ from _typeshed import StrOrBytesPath
|
|
|
+
|
|
|
+def oneliner(*args) -> str:
|
|
|
+ return subprocess.run(args, check=True, capture_output=True, text=True).stdout.strip()
|
|
|
|
|
|
commit = oneliner('git', 'rev-parse', 'HEAD')
|
|
|
local_branch = oneliner('git', 'branch', '--show-current')
|
|
|
@@ -39,18 +45,18 @@ if hostname.startswith('github.com-'):
|
|
|
|
|
|
obj_type = 'tree'
|
|
|
if len(sys.argv) == 2:
|
|
|
- obj_type = 'blob'
|
|
|
+ obj_type = 'blob'
|
|
|
|
|
|
repo_url = urllib.parse.urlunparse(('https', hostname, parsed.path, '', '', ''))
|
|
|
|
|
|
-def url_for(treeish):
|
|
|
- dir_url = '%s/%s/%s' % (repo_url, obj_type, treeish)
|
|
|
- if relpath:
|
|
|
- dir_url = '%s/%s' % (dir_url, relpath)
|
|
|
- if len(sys.argv) == 2:
|
|
|
- return '%s/%s' % (dir_url, sys.argv[1])
|
|
|
- else:
|
|
|
- return dir_url
|
|
|
+def url_for(treeish: str) -> str:
|
|
|
+ dir_url = '%s/%s/%s' % (repo_url, obj_type, treeish)
|
|
|
+ if relpath:
|
|
|
+ dir_url = '%s/%s' % (dir_url, relpath)
|
|
|
+ if len(sys.argv) == 2:
|
|
|
+ return '%s/%s' % (dir_url, sys.argv[1])
|
|
|
+ else:
|
|
|
+ return dir_url
|
|
|
|
|
|
if tag is not None:
|
|
|
print(url_for(tag))
|