Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow full url in plugin_name #73

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions zap.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ plug() {
else
local full_plugin_name="$1"
local git_ref="$2"
local plugin_name=$(echo "$full_plugin_name" | cut -d "/" -f 2)
local plugin_name=$(echo "$plugin" | awk -F / '{print $NF}')
plugin_name="${plugin_name/.git/}"
local plugin_dir="$ZAP_PLUGIN_DIR/$plugin_name"
if [ ! -d "$plugin_dir" ]; then
echo "🔌$plugin_name"
git clone "https://github.com/${full_plugin_name}.git" "$plugin_dir" > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "Failed to clone $plugin_name" && return 1; fi

git clone $full_plugin_name --depth 1 "$plugin_dir" > /dev/null 2>&1
if [ $? -ne 0 ]; then
git clone "https://github.com/$full_plugin_name.git" --depth 1 "$plugin_dir" > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "Failed to clone $plugin_name" && return 1; fi
fi
if [ -n "$git_ref" ]; then
git -C "$plugin_dir" checkout "$git_ref" > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "Failed to checkout $git_ref" && return 1; fi
Expand All @@ -41,14 +44,14 @@ plug() {
_try_source "$plugin_dir/$plugin_name.zsh-theme"
fi
if [[ -n $full_plugin_name ]]; then
echo "$full_plugin_name" >> "$HOME/.local/share/zap/installed_plugins"
echo "$full_plugin_name" >> "$ZAP_DIR/installed_plugins"
fi
}

_pull() {
echo "🔌 $1"
git pull > /dev/null 2>&1
if [ $? -ne 0 ]; then echo "Failed to update $1" && exit 1; fi
if [ $? -ne 0 ]; then echo "Failed to update $1" && return 1; fi
echo -e "\e[1A\e[K⚡ $1"
}

Expand Down Expand Up @@ -95,11 +98,22 @@ _zap_update() {
_pull 'zap'
cd $pwd
else
for plug in $plugins; do
selected=$(echo $plug | grep -E "^ $plugin" | awk 'BEGIN { FS = "[ /]" } { print $6 }')
cd "$ZAP_PLUGIN_DIR/$selected"
_pull $selected
cd - > /dev/null 2>&1
selected_number=($(echo $plugin | awk -F '[[:space:]]' '{print $0}'))
sorted=($(printf '%s\n' "${selected_number[@]}"|sort -u))
for item in $sorted;do
for plug in $plugins; do
selected=$(echo $plug | grep -E "^ ${item##*( )}" | awk -F / '{print $NF}')
selected="${selected/.git/}"
if [[ -n $selected ]]; then
if [[ -d "$ZAP_PLUGIN_DIR/$selected" ]];then
cd "$ZAP_PLUGIN_DIR/$selected"
_pull $selected
cd - > /dev/null 2>&1
fi
else
echo " ${item##*( )} is not a valid option!"
fi
done
done
fi
if [[ $ZAP_CLEAN_ON_UPDATE == true ]]; then
Expand Down