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

Merge comp into plug #18

Merged
merged 10 commits into from
Nov 11, 2022

Conversation

Granddave
Copy link
Member

@Granddave Granddave commented Nov 9, 2022

Fixes #17

I tried to merge the two functions but am not sure that zapcomp really worked before.
There are two fpath+= but I guess that only one is needed? I.e. this one: fpath+=$("$completion_file_path"), and scrap fpath+="$(dirname "$plugin_dir")"..?

I am also not sure that this kind of variable operation ${completion_file:1} is valid POSIX, so changing #!/bin/sh to #!/bin/zsh (or just remove the shebang since it's not supposed to be run anyway) would be better.

Also, updated the way download progress is shown. Now the plug is shown during the download and when it's finished the icon will change to the lightning bolt :)

2022-11-09_21-36

Since this function is meant to be used locally we can prefix it with
underscore to hint that this function shouldn't be used externally. Also
the function doesn't return any status value which makes the `||`
unnecessary and since we check that the file exist before sourcing it's
not a problem to `_try_source` a non-existing file.
Once the plugin is downloaded the plug emoji will be replaced with a
lightning bolt. :^)
@Granddave Granddave changed the title Merge comp into plug - Fixes #17 Merge comp into plug Nov 9, 2022
@ChristianChiarulli
Copy link
Member


export ZAP_DIR="$HOME/.local/share/zap"
export ZAP_PLUGIN_DIR="$ZAP_DIR/plugins"

function _try_source() {
    # shellcheck disable=SC1090
    [ -f "$1" ] && source "$1"
}

function zapplug() {
    local full_plugin_name="$1"
    local initialize_completion="$2"
    local plugin_name=$(echo "$full_plugin_name" | cut -d "/" -f 2)
    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 install $plugin_name"
            exit 1
        fi
        echo -e "\e[1A\e[K⚡$plugin_name"
    fi
    _try_source "$plugin_dir/$plugin_name.plugin.zsh"
    _try_source "$plugin_dir/$plugin_name.zsh"
    _try_source "$plugin_dir/$plugin_name.zsh-theme"
}

I don't think we even need the completion part tbh

@ChristianChiarulli ChristianChiarulli added the enhancement New feature or request label Nov 11, 2022
@ChristianChiarulli ChristianChiarulli merged commit 9ddf803 into zap-zsh:master Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[spike]: see if it is possible to merge zapcmp and zapplug
2 participants