Skip to content

Commit

Permalink
remove function and refactor zpath to accomodate
Browse files Browse the repository at this point in the history
  • Loading branch information
thornjad committed Mar 8, 2023
1 parent 4bae5ba commit b481123
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions zpico.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ typeset ZP_HOME=${0:A:h}
typeset ZP_PLUGIN_HOME=${ZP_PLUGIN_HOME:-${HOME}/.local/share/zpico/plugins}

_zpico_add() {
local supportedSources=(github gitlab framagit local)
local supportedSources=(github gitlab framagit codeberg local)
local zsource="github" zbranchcmd="" zuse=""
local zmodule=${1:t} zurl=${1}
local zmodule=${1:t} zrepo=${1}
local zpath=${ZP_PLUGIN_HOME}/${zmodule}

if [[ -n "$(ls -A $zpath)" ]]; then
echo "Package path for $zmodule already exists!"
echo "Use 'zpico remove ${zmodule}' or remove ${zpath} first."
return 1
fi

for x in "$@"; do
parts=(${(s/:/)x})
case ${parts[1]} in
Expand All @@ -34,13 +42,11 @@ _zpico_add() {
esac
done

local sourceurl="https://${zsource}.com/${zurl}.git"
local sourceurl="https://${zsource}.com/${zrepo}.git"
if [[ "$zsource" =~ "local" ]]; then
sourceurl="${zurl}.git"
sourceurl="${zrepo}.git"
fi

local zpath=${ZP_PLUGIN_HOME}/${zmodule}

if [[ ! -d ${zpath} ]]; then
mkdir -p ${zpath}
git clone --recursive ${zbranchcmd} ${sourceurl} ${zpath}
Expand All @@ -52,6 +58,19 @@ _zpico_add() {
fi
}

_zpico_remove() {
local zpath=${ZP_PLUGIN_HOME}/${1:t}
rm -rf $zpath
}

_zpico_remove_all() {
read "choice?Remove all downloaded plugins [y/N]? "
if [[ ${${choice:0:1}:l} = "y" ]]; then
echo "Removing all downloaded plugins... "
rm -rf ${ZP_PLUGIN_HOME}
fi
}

_zpico_update() {
git -C "${ZP_PLUGIN_HOME}/${1:t}" pull -q --no-rebase
git -C "${ZP_PLUGIN_HOME}/${1:t}" submodule update
Expand Down Expand Up @@ -94,10 +113,26 @@ _zpico_help() {
}

zpico() {
local zmodule="$2"

case "$1" in
add)
_zpico_add "$2" "$3" "$4" "$5"
;;
remove)
case ${zmodule} in
"")
_zpico_help
;;
"--all")
_zpico_remove_all
;;
*)
echo "Removing ${zmodule}..."
_zpico_assert_exists $zmodule && _zpico_remove $zmodule
;;
esac
;;
update)
case ${zmodule} in
"")
Expand Down

0 comments on commit b481123

Please sign in to comment.