From 5b418806492969ddb852004d5e521560b9025af4 Mon Sep 17 00:00:00 2001
From: merakor <cem@ckyln.com>
Date: Wed, 12 Aug 2020 09:33:22 +0000
Subject: cpt-owns: deal with relative path and commands, change output format

FossilOrigin-Name: 687c0e54d5330a6f2a624cd062ffda9ec605cd12ee367a7eaa3b972c962cf702
---
 contrib/cpt-owns | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

(limited to 'contrib/cpt-owns')

diff --git a/contrib/cpt-owns b/contrib/cpt-owns
index 60c4633..5f73674 100755
--- a/contrib/cpt-owns
+++ b/contrib/cpt-owns
@@ -3,6 +3,17 @@
 
 case "$1" in ''|--help|-h) printf '%s\n' "usage: ${0##*/} [file]" ; exit 0 ; esac
 
+# If full path is not specified, use either the current directory, or look for
+# a command.
+case "$1" in /*) ;;
+    *)
+        if [ -f "$1" ]; then
+            set -- "$PWD/$1"
+        else
+            set -- "$(command -v "$1")"
+        fi
+esac
+
 # Strip 'CPT_ROOT' from the file path if passed and
 # follow symlinks.
 file="${1#$CPT_ROOT}"
@@ -27,4 +38,4 @@ pkg_owns=$(grep -lFx "${file#$CPT_ROOT}" \
 pkg_owns=${pkg_owns%/*}
 pkg_owns=${pkg_owns##*/}
 
-printf '%s\n' "[$pkg_owns] owns '$1'"
+printf '%s\n' "$pkg_owns"
-- 
cgit v1.2.3