Update from updated-inputs-2025-05-26-01-03
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
{ config, ... }:
|
{ config, lib, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
environment.sessionVariables = {
|
environment.sessionVariables = {
|
||||||
REQUESTS_CA_BUNDLE = config.security.pki.caBundle;
|
REQUESTS_CA_BUNDLE = mkDefault config.security.pki.caBundle;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -4,17 +4,26 @@ import argparse
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
REMOTE_TYPES = {
|
REMOTE_TYPES = {
|
||||||
"github": {
|
"github": {
|
||||||
"match": re.compile(r'git@github.com:(?P<username>[\w\.-]+)/(?P<project>[\w\.-]+).git'),
|
"match": re.compile(r'git@github.com:(?P<username>[\w\.-]+)/(?P<project>[\w\.-]+).git'),
|
||||||
"format-branch": lambda g: f"https://github.com/{g.username}/{g.project}/tree/{g.branch}/",
|
"format-branch": lambda g: f"https://github.com/{g.username}/{g.project}/tree/{g.branch}/",
|
||||||
|
"format-branch-file": lambda g: f"https://github.com/{g.username}/{g.project}/blob/{g.branch}/{g.file}",
|
||||||
|
"format-branch-dir": lambda g: f"https://github.com/{g.username}/{g.project}/tree/{g.branch}/{g.dir}",
|
||||||
"format-commit": lambda g: f"https://github.com/{g.username}/{g.project}/commit/{g.commit}/",
|
"format-commit": lambda g: f"https://github.com/{g.username}/{g.project}/commit/{g.commit}/",
|
||||||
|
"format-commit-file": lambda g: f"https://github.com/{g.username}/{g.project}/blob/{g.commit}/{g.file}",
|
||||||
|
"format-commit-dir": lambda g: f"https://github.com/{g.username}/{g.project}/tree/{g.commit}/{g.dir}",
|
||||||
},
|
},
|
||||||
"gitea": {
|
"gitea": {
|
||||||
"match": re.compile(r'(?P<gituser>[\w\.-]+)@(?P<host>[\w\.-]+):(?P<username>[\w\.-]+)/(?P<project>[\w\.-]+).git'),
|
"match": re.compile(r'(?P<gituser>[\w\.-]+)@(?P<host>[\w\.-]+):(?P<username>[\w\.-]+)/(?P<project>[\w\.-]+).git'),
|
||||||
"format-branch": lambda g: f"https://{g.host}/{g.username}/{g.project}/src/branch/{g.branch}/",
|
"format-branch": lambda g: f"https://{g.host}/{g.username}/{g.project}/src/branch/{g.branch}/",
|
||||||
|
"format-branch-file": lambda g: f"https://{g.host}/{g.username}/{g.project}/src/branch/{g.branch}/{g.file}",
|
||||||
|
"format-branch-dir": lambda g: f"https://{g.host}/{g.username}/{g.project}/src/branch/{g.branch}/{g.dir}",
|
||||||
"format-commit": lambda g: f"https://{g.host}/{g.username}/{g.project}/commit/{g.commit}/",
|
"format-commit": lambda g: f"https://{g.host}/{g.username}/{g.project}/commit/{g.commit}/",
|
||||||
|
"format-commit-file": lambda g: f"https://{g.host}/{g.username}/{g.project}/src/commit/{g.commit}/{g.file}",
|
||||||
|
"format-commit-dir": lambda g: f"https://{g.host}/{g.username}/{g.project}/src/commit/{g.commit}/{g.dir}",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,15 +35,25 @@ class FormatArgs:
|
|||||||
project: str = None
|
project: str = None
|
||||||
commit: str = None
|
commit: str = None
|
||||||
branch: str = None
|
branch: str = None
|
||||||
|
file: str = None
|
||||||
|
dir: str = None
|
||||||
|
|
||||||
def is_git_repo():
|
def is_git_repo():
|
||||||
s = subprocess.run(["git", "rev-parse"], capture_output=True, text=True)
|
s = subprocess.run(["git", "rev-parse"], capture_output=True, text=True)
|
||||||
|
|
||||||
return s.returncode == 0
|
return s.returncode == 0
|
||||||
|
|
||||||
|
def get_git_dir():
|
||||||
|
s = subprocess.run(["git", "rev-parse", "--show-toplevel"], capture_output=True, text=True)
|
||||||
|
return Path(s.stdout.strip())
|
||||||
|
|
||||||
def get_remote_branch():
|
def get_remote_branch():
|
||||||
s = subprocess.run(["git", "status", "--porcelain", "-uno", "-b", "--no-ahead-behind"], capture_output=True, text=True)
|
s = subprocess.run(["git", "status", "--porcelain", "-uno", "-b", "--no-ahead-behind"], capture_output=True, text=True)
|
||||||
|
|
||||||
|
if s.stdout.startswith("## HEAD (no branch)"):
|
||||||
|
print("Detached head, can't link")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
git_status_branch_info = s.stdout.splitlines()[0][3:].split()[0]
|
git_status_branch_info = s.stdout.splitlines()[0][3:].split()[0]
|
||||||
|
|
||||||
branches = git_status_branch_info.split("...")
|
branches = git_status_branch_info.split("...")
|
||||||
@@ -70,6 +89,7 @@ def main():
|
|||||||
prog='git-show-link',
|
prog='git-show-link',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument("path", nargs="?", default=None, help="Path to link to specific file or directory")
|
||||||
parser.add_argument("--branch", dest="display_branch", action='store_true', help="Display link to branch, instead to commit")
|
parser.add_argument("--branch", dest="display_branch", action='store_true', help="Display link to branch, instead to commit")
|
||||||
parser.add_argument("--remote-type", dest="remote_type", choices=REMOTE_TYPES.keys(), help="Specify remote type")
|
parser.add_argument("--remote-type", dest="remote_type", choices=REMOTE_TYPES.keys(), help="Specify remote type")
|
||||||
|
|
||||||
@@ -80,6 +100,8 @@ def main():
|
|||||||
|
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
git_dir_path = get_git_dir()
|
||||||
|
|
||||||
r = get_remote_branch()
|
r = get_remote_branch()
|
||||||
|
|
||||||
remote_url = get_remote_url(r["remote"])
|
remote_url = get_remote_url(r["remote"])
|
||||||
@@ -103,13 +125,47 @@ def main():
|
|||||||
|
|
||||||
g = FormatArgs(**m.groupdict())
|
g = FormatArgs(**m.groupdict())
|
||||||
|
|
||||||
if args.display_branch:
|
if args.path is not None:
|
||||||
g.branch = r["branch"]
|
path = Path(args.path).absolute()
|
||||||
print(remote_type["format-branch"](g))
|
path = path.relative_to(git_dir_path)
|
||||||
|
|
||||||
|
if path.is_dir():
|
||||||
|
path = str(path)
|
||||||
|
|
||||||
|
if path == ".":
|
||||||
|
path = ""
|
||||||
|
else:
|
||||||
|
path += "/"
|
||||||
|
|
||||||
|
g.dir = path
|
||||||
|
else:
|
||||||
|
g.file = str(path)
|
||||||
|
|
||||||
|
if g.file is not None:
|
||||||
|
if args.display_branch:
|
||||||
|
g.branch = r["branch"]
|
||||||
|
print(remote_type["format-branch-file"](g))
|
||||||
|
else:
|
||||||
|
commit = get_last_commit()
|
||||||
|
g.commit = commit
|
||||||
|
print(remote_type["format-commit-file"](g))
|
||||||
|
elif g.dir is not None:
|
||||||
|
if args.display_branch:
|
||||||
|
g.branch = r["branch"]
|
||||||
|
print(remote_type["format-branch-dir"](g))
|
||||||
|
else:
|
||||||
|
commit = get_last_commit()
|
||||||
|
g.commit = commit
|
||||||
|
print(remote_type["format-commit-dir"](g))
|
||||||
else:
|
else:
|
||||||
commit = get_last_commit()
|
if args.display_branch:
|
||||||
g.commit = commit
|
g.branch = r["branch"]
|
||||||
print(remote_type["format-commit"](g))
|
print(remote_type["format-branch"](g))
|
||||||
|
else:
|
||||||
|
commit = get_last_commit()
|
||||||
|
g.commit = commit
|
||||||
|
print(remote_type["format-commit"](g))
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if not remote_type_found:
|
if not remote_type_found:
|
||||||
|
Reference in New Issue
Block a user