jmalloc / grit

Keep track of your local Git clones.
MIT License
22 stars 3 forks source link

Shell integration: "(eval):19: command not found: complete" #46

Closed ezzatron closed 3 years ago

ezzatron commented 7 years ago

This error happens when I try to use shell integration. It's due to "complete" being a Bash function, and I'm using Zsh. There are ways around it on my end, but they will apparently slow down my Zsh.

jmalloc commented 7 years ago

For my own reference:

ezzatron commented 7 years ago

Based on some stack overflow answer I read, that ^ is kinda the cheating way, that supposedly makes Zsh slower. I assume that there are comparable Zsh completion features that can be used instead of simply polyfilling for Bash's features.

jmalloc commented 7 years ago

If you run grit shell-integration you will see what's getting added to .bash_profile for bash users -- very happy to detect zsh and add support to this command (which is hidden from the command list, btw).

20:16 jmalloc/grit master: grit shell-integration

grit() {
    local file="$(mktemp)"
    trap "rm -f '$file'" EXIT
    "/Users/james/bin/grit" --with-shell-integration="$file" "$@" && source "$file"
    return $?
}

# Setup autocompletion using the real binary.
_grit_bash_autocomplete() {
    local cur opts base
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    opts=$(GRIT_COMP_WORDS="${COMP_WORDS[@]}" "/Users/james/bin/grit" ${COMP_WORDS[@]:1:$COMP_CWORD} --generate-bash-completion)
    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    return 0
}

complete -F _grit_bash_autocomplete grit
jmalloc commented 3 years ago

I am using a completely different CLI library in v2.0.0, which natively supports zsh completion. I don't intend to fix this in version 1.