aboutsummaryrefslogtreecommitdiff
path: root/contrib/cpt-link
blob: 7b1226e6cdb98c03a82d538f7daac30321e0207c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh -ef
# Link a forked package's files to the other repository

## SYNOPSIS:
## .Nm
## .Op Fl p Ar package
## .Op Ar file...

## 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

usage() {
    printf 'usage: %s [-p package] [file...]\n' "${0##*/}"
    exit 0
}

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"
    printf 'linked %s to %s\n' "$oPKG/$file" "$PWD/$file"
done