From 86591b4ecacf708107220861168944124bcf8d93 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Fri, 13 Mar 2020 13:43:53 +0000 Subject: contrib: Added kiss-[fork,link] FossilOrigin-Name: ac16762d076744841d4162ba4c4d99fd0ae6836afd90169d6cb25404e5297601 --- contrib/kiss-fork | 17 +++++++++++++++++ contrib/kiss-link | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 contrib/kiss-fork create mode 100755 contrib/kiss-link diff --git a/contrib/kiss-fork b/contrib/kiss-fork new file mode 100755 index 0000000..6e1245c --- /dev/null +++ b/contrib/kiss-fork @@ -0,0 +1,17 @@ +#!/bin/sh -ef + +kiss s "${1:-null}" >/dev/null || { + printf 'usage: kiss-fork pkg_name\n' + exit 1 +} + +# Disable this warning as globbing is disabled and word splitting +# is intentional. This grabs the location of the package's files. +# shellcheck disable=2046 +( + set -- $(kiss s "$1") + + cp -r "$1" . +) + +printf 'forked package to %s\n' "$PWD/$1" diff --git a/contrib/kiss-link b/contrib/kiss-link new file mode 100755 index 0000000..9412917 --- /dev/null +++ b/contrib/kiss-link @@ -0,0 +1,45 @@ +#!/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 + +# 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 + + # Finally, make the link to the file in whatever repository + # it was found in. + ln -sf "$1/$file" "$file" +} + +printf 'linked %s to %s\n' "$file" "$1" -- cgit v1.2.3