From 06df59895003d76529e5e4ccf348fcf092e76448 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Mon, 2 Sep 2024 01:38:32 +0200 Subject: feat[po] using gh-which-pr open first current PR on GitHub. --- po | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'po') diff --git a/po b/po index 1ae36fb..a2ac3a8 100755 --- a/po +++ b/po @@ -1,4 +1,6 @@ #!/bin/sh +set -eux + if [ ! -d .osc ] && [ ! -d .git ] ; then echo 'This program must be run from an project directory.' exit 42 @@ -14,22 +16,27 @@ elif [ -f .osc/_package ] ; then project=$(cat .osc/_project) package=$(cat .osc/_package) o_url="${apiurl}/package/show/${project}/${package}" -elif [ -d .git ] ; then - if git remote show gitlab >/dev/null 2>&1 ; then - o_url="$(git remote get-url gitlab)" - elif git remote show github >/dev/null 2>&1 ; then - o_url="$(git remote get-url github)" - elif git remote show sourcehut >/dev/null 2>&1 ; then - o_url="$(git remote get-url sourcehut)" - elif git remote show myrepo >/dev/null 2>&1 ; then - o_url="$(git remote get-url myrepo)" - elif git remote show origin >/dev/null 2>&1 ; then - o_url="$(git remote get-url origin)" - else - exit 0 - fi -else - exit 0 fi -xdg-open "$o_url" >/dev/null 2>&1 +if [ -z "$o_url" ] ; then + pr_url="$(gh-which-pr)" || true + if [ -n "$pr_url" ] ; then + o_url="$pr_url" + elif [ -d .git ] ; then + if git remote show gitlab >/dev/null 2>&1 ; then + o_url="$(git remote get-url gitlab)" + elif git remote show github >/dev/null 2>&1 ; then + o_url="$(git remote get-url github)" + elif git remote show sourcehut >/dev/null 2>&1 ; then + o_url="$(git remote get-url sourcehut)" + elif git remote show myrepo >/dev/null 2>&1 ; then + o_url="$(git remote get-url myrepo)" + elif git remote show origin >/dev/null 2>&1 ; then + o_url="$(git remote get-url origin)" + else + exit 0 + fi + fi +fi + +[ -z "$o_url" ] || xdg-open "$o_url" >/dev/null 2>&1 -- cgit