aboutsummaryrefslogtreecommitdiff
path: root/contrib/cpt-link
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-03-12 12:22:51 +0000
committermerakor <cem@ckyln.com>2021-03-12 12:22:51 +0000
commitd3671bcb629260b2a0acfa0357df6d15903ba898 (patch)
tree39014e592f7b0a7554f95faede96eeb124691e74 /contrib/cpt-link
parent81e3f00288d6fdc93de2dc31c065ebe3bdb1adf5 (diff)
downloadcpt-d3671bcb629260b2a0acfa0357df6d15903ba898.tar.gz
cpt-link: change usage, add documentation
cpt-link now uses '-p' flag for specifying a package. FossilOrigin-Name: 74b38d49d091c6daeb93a27882906117bdaf655c79d4264474517253fab1d696
Diffstat (limited to 'contrib/cpt-link')
-rwxr-xr-xcontrib/cpt-link39
1 files changed, 32 insertions, 7 deletions
diff --git a/contrib/cpt-link b/contrib/cpt-link
index b6a0c57..7b1226e 100755
--- a/contrib/cpt-link
+++ b/contrib/cpt-link
@@ -1,16 +1,41 @@
#!/bin/sh -ef
# Link a forked package's files to the other repository
-case "$1" in ''|--help|-h) printf '\033[1;33m-> \033[musage: %s [file...]\n' "${0##*/}" ; exit 0 ; esac
+## SYNOPSIS:
+## .Nm
+## .Op Fl p Ar package
+## .Op Ar file...
-# Check if the package exists in a repository and error out here
-# if it does not. The error message from the package manager will
-# be displayed.
-cpt-search "${PKG:=${PWD##*/}}" >/dev/null
+## DESCRIPTION:
+## .Nm
+## symlinks files to the current package directory from a separate instance of
+## the same package. If the
+## .Fl p
+## flag and a
+## .Ar package
+## is specified,
+## .Nm
+## will link files from the given package instead.
+##
+## .Nm
+## creates symbolic links of package files using the realpath of the file, so it
+## is therefore not suitable for using within a git repository, and should only
+## be used internally.
+## see: cpt-fork.1
-oPKG="$(cpt-search "$PKG" | grep -v "^$PWD\$\|/var/db/cpt/installed/$PKG" | sed 1q)"
+usage() {
+ printf 'usage: %s [-p package] [file...]\n' "${0##*/}"
+ exit 0
+}
-for file in "$@" ; do
+case "$1" in
+ -p) pkg=$2; shift 2 ;;
+ -h|--help|'') usage ;;
+esac
+
+oPKG="$(cpt-search -sd "${pkg:--o}")"
+
+for file; do
[ -e "${oPKG:?}/$file" ]
[ -d "$file" ] && rm -rf "$file"
ln -sf "$oPKG/$file" "$file"