diff options
author | merakor <cem@ckyln.com> | 2020-04-04 20:41:36 +0000 |
---|---|---|
committer | merakor <cem@ckyln.com> | 2020-04-04 20:41:36 +0000 |
commit | c3d0cccd2fc9f06835e2b999b36fd556619a3d42 (patch) | |
tree | 98c5ed9c295d8dfab7980c5018004da7cfee826f | |
parent | 6a3d8f9a449a0c9ee955c2422872607ec36c626b (diff) | |
download | cpt-c3d0cccd2fc9f06835e2b999b36fd556619a3d42.tar.gz |
kiss-link: simplify and add support for multiple files
FossilOrigin-Name: 03cc682f239f9ccad5b96211ce18939ceef22f64ec4fcc59707a7a6487fc3290
-rwxr-xr-x | contrib/kiss-link | 45 |
1 files changed, 8 insertions, 37 deletions
diff --git a/contrib/kiss-link b/contrib/kiss-link index 9412917..1c0b2db 100755 --- a/contrib/kiss-link +++ b/contrib/kiss-link @@ -1,45 +1,16 @@ #!/bin/sh -ef -[ "$1" ] || { - printf 'usage: kiss-link file\n' - exit 1 -} - -[ -f "${file:=$1}" ] || { - printf 'file %s does not exist in the current directory\n' "$1" - exit 1 -} - -oPWD=$PWD +[ "$1" ] || { printf 'usage: kiss-link [file] [file]\n' ; exit 0 ;} # 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. -kiss s "${PWD##*/}" >/dev/null - -# Disable this warning as globbing is disabled and word splitting -# is intentional. This grabs the location of the package's files. -# shellcheck disable=2046 -{ - # Generate a list of repositories in which the package - # exists. Then 'cd' to the first found directory to do a - # comparison. - set -- $(kiss s "${PWD##*/}"); cd "$1" - - # Error if the package exists nowhere but the current - # directory and this script would create a broken symlink. - [ -z "$2" ] && [ "$PWD" = "$oPWD" ] && { - printf 'error: cannot symlink file to itself\n' - exit 1 - } - - # If the first repository in '$KISS_PATH' is the current - # directory, use the second repository in the list. - [ "$PWD" = "$oPWD" ] && shift +kiss s "${PKG:=${PWD##*/}}" >/dev/null - # Finally, make the link to the file in whatever repository - # it was found in. - ln -sf "$1/$file" "$file" -} +oPKG="$(kiss s "$PKG" | grep -v "^$PWD\$\|/var/db/kiss/installed/$PKG" | sed 1q)" -printf 'linked %s to %s\n' "$file" "$1" +for file in "$@" ; do + [ -e "${oPKG:?}/$file" ] + ln -sf "$oPKG/$file" "$file" + printf 'linked %s to %s\n' "$oPKG/$file" "$PWD/$file" +done |