diff options
author | merakor <cem@ckyln.com> | 2020-08-12 09:33:22 +0000 |
---|---|---|
committer | merakor <cem@ckyln.com> | 2020-08-12 09:33:22 +0000 |
commit | 5b418806492969ddb852004d5e521560b9025af4 (patch) | |
tree | 90f7b11372674c97158e5e75f30ed7d431e6ccff | |
parent | b44c3f34e9768201a540ac36c3a525f7effb6778 (diff) | |
download | cpt-5b418806492969ddb852004d5e521560b9025af4.tar.gz |
cpt-owns: deal with relative path and commands, change output format
FossilOrigin-Name: 687c0e54d5330a6f2a624cd062ffda9ec605cd12ee367a7eaa3b972c962cf702
-rwxr-xr-x | contrib/cpt-owns | 13 |
1 files changed, 12 insertions, 1 deletions
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" |