diff --git a/bpkg-source b/bpkg-source new file mode 120000 index 0000000..b8244ef --- /dev/null +++ b/bpkg-source @@ -0,0 +1 @@ +lib/source/source.sh \ No newline at end of file diff --git a/lib/install/install.sh b/lib/install/install.sh index f10c3d1..7758e6a 100755 --- a/lib/install/install.sh +++ b/lib/install/install.sh @@ -420,7 +420,7 @@ bpkg_install_from_remote () { ## shallow clone info "Cloning $repo_url to $(pwd)/$name-$version" - git clone "$repo_url" "$name-$version" && ( + (test -d "$name-$version" || git clone "$repo_url" "$name-$version") && ( ## move into directory cd "$name-$version" && ( ## checkout to branch version or checkout into diff --git a/lib/run/run.sh b/lib/run/run.sh index 3ee2f71..a9d5ed0 100755 --- a/lib/run/run.sh +++ b/lib/run/run.sh @@ -38,9 +38,14 @@ usage () { bpkg_run () { pushd . >/dev/null || return $? + + local should_emit_source=0 + local should_source=0 + local should_clean=0 local ignore_args=0 local needs_name=0 local package='' + local dest='' local name='' for opt in "$@"; do @@ -54,9 +59,22 @@ bpkg_run () { -s|--source) if (( 0 == ignore_args )); then - # shellcheck disable=SC1090 - source "$(which "$name")" - return $? + should_source=1 + shift + fi + ;; + + --emit-source) + if (( 0 == ignore_args )); then + should_emit_source=1 + shift + fi + ;; + + -c|--clean) + if (( 0 == ignore_args )); then + should_clean=1 + shift fi ;; @@ -78,7 +96,12 @@ bpkg_run () { esac done - local dest=$(bpkg_install --no-prune -g "$1" 2>/dev/null | grep 'info: Cloning' | sed 's/.* to //g' | xargs echo) + if (( 0 == should_clean )); then + dest=$(bpkg_install --no-prune -g "$1" 2>/dev/null | grep 'info: Cloning' | sed 's/.* to //g' | xargs echo) + else + dest=$(bpkg_install -g "$1" 2>/dev/null | grep 'info: Cloning' | sed 's/.* to //g' | xargs echo) + fi + if [ -z "$dest" ]; then return $?; fi @@ -90,7 +113,18 @@ bpkg_run () { shift popd >/dev/null || return $? - eval "$(which "$name")" $@ + + if (( 1 == should_emit_source )); then + which "$name" + else + if (( 1 == should_source )); then + # shellcheck disable=SC1090 + source "$(which "$name")" + else + eval "$(which "$name")" $@ + fi + fi + return $? } diff --git a/lib/source/source.sh b/lib/source/source.sh new file mode 100755 index 0000000..37018a3 --- /dev/null +++ b/lib/source/source.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if ! type -f bpkg-run &>/dev/null; then + echo "error: bpkg-run not found, aborting" + exit 1 +else + # shellcheck disable=SC2230 + # shellcheck source=lib/run/run.sh + source "$(which bpkg-run)" +fi + +bpkg_source () { + bpkg_run --emit-source $@ + return $? +} + +## Use as lib or perform install +if [[ ${BASH_SOURCE[0]} != "$0" ]]; then + export -f bpkg_source +elif validate_parameters; then + bpkg_source "$@" + exit $? +else + #param validation failed + exit $? +fi diff --git a/lib/term/term.sh b/lib/term/term.sh index 04fad0f..7dc46d1 100755 --- a/lib/term/term.sh +++ b/lib/term/term.sh @@ -286,6 +286,19 @@ term () { ## main function with args if [[ ${BASH_SOURCE[0]} != "$0" ]]; then export -f term + export -f term_dim + export -f term_move + export -f term_reset + export -f term_write + export -f term_clear + export -f term_color + export -f term_blink + export -f term_cursor + export -f term_bright + export -f term_reverse + export -f term_underline + export -f term_transition + export -f term_background else term "${@}" fi diff --git a/setup.sh b/setup.sh index 5fcfb54..5c135b3 100755 --- a/setup.sh +++ b/setup.sh @@ -69,7 +69,7 @@ if [ -z "$PREFIX" ]; then fi # All 'bpkg' supported commands -CMDS="json install package term suggest init utils update list show getdeps run" +CMDS="json install package term suggest init utils update list show getdeps run source" make_install () { local source