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

Trouble getting zsh completion to work #31

Closed
RichardBronosky opened this issue May 9, 2021 · 3 comments
Closed

Trouble getting zsh completion to work #31

RichardBronosky opened this issue May 9, 2021 · 3 comments
Labels
question Further information is requested

Comments

@RichardBronosky
Copy link

By reading the source code, I found the undocumented feature of flavours —completions zsh. But eval-ing it doesn’t work, and redirecting it to a file and sourcing it doesn’t work.

❯ flavours --completions zsh > /tmp/flavours.completions.zsh


❯ eval "$(flavours --completions zsh)"
_arguments:comparguments:325: can only be called from completion function


❯ source /tmp/flavours.completions.zsh
_arguments:comparguments:325: can only be called from completion function

Any help would be appreciated. (I have used bash since 1995 and just switched to zsh a few months ago, so I'm out of my element here.)

@Misterio77
Copy link
Owner

Misterio77 commented May 9, 2021

Hey!

Normally you don't eval completions, if i'm not mistaken.
I think (assuming you've already compinited somewhere on your .zshrc) there might be a user-wide directory for zsh completions, but i'm not really sure where it is. I do know you can place system-wide completions on /usr/share/zsh/site-functions.

About the --completions option, i didn't document it because it is not really as featureful as i wanted (i manually tweak them, so flavours apply can manually complete scheme names, for example). You can find the correct completions already generated on the completions folder on the repo.

Not sure which distro you use, but the AUR package does exactly that. It takes the zsh completion (on the folder i mentioned) and copies it to a file named _flavours on the /usr/share/zsh/site-functions/ directory. So just doing that should do the trick for you too!

Let me know if that gets you going.

@Misterio77 Misterio77 added the question Further information is requested label May 9, 2021
@Misterio77
Copy link
Owner

Actually here's an issue related: #4

@RichardBronosky
Copy link
Author

Hey, thanks for the reply. You were correct about needing to add a symlink to a dir in the $fpath. That did get it working for me. I waited to reply because I wanted to get a solution together for others to benefit from.

Here is how I recommend bootstrapping macOS:

#!/usr/bin/env bash

## Recommended ENV vars and paths
CARGO_HOME="$HOME/.local/share/cargo"
FLAVOURS_CONFIG_FILE="$HOME/.config/flavours/config.toml"
FLAVOURS_DATA_DIRECTORY="$HOME/.local/share/flavours"

## May vary by user
SRC_DIRECTORY="$HOME/src/"
COMPLETIONS_DIRECTORY="$HOME/.local/share/zsh/site-functions"
SHELL_PROFILE="$HOME/.config/shell/profile"

## Ensure presence of ENV vars
for var_name in "CARGO_HOME" "FLAVOURS_DATA_DIRECTORY" "FLAVOURS_CONFIG_FILE"; do
    if ! grep -q $var_name "$SHELL_PROFILE"; then
        # SEE: https://mywiki.wooledge.org/BashFAQ/006#Evaluating_indirect.2Freference_variables
        if [[ -n "${ZSH_VERSION:-}" ]]; then
            var_value="${(P)var_value}"
        elif [[ -n "${BASH_VERSION:-}" ]]; then
            var_value="${!var_value}"
        fi
        # or if you are not opposed to eval...
        #   eval "var_value=\"\${$var_value}\""
        var_value="${var_value/$HOME/\$HOME}"
        echo "var_name=\"${var_value}\"" >> "$SHELL_PROFILE"
    fi
done

## Ensure presence of directories
for dir in \
        "$(dirname $FLAVOURS_CONFIG_FILE)" "$FLAVOURS_DATA_DIRECTORY" \
        "$SRC_DIRECTORY" "$COMPLETIONS_DIRECTORY" "$CARGO_HOME"; do
    [[ -d "$dir" ]] || mkdir -p "$dir"
done

brew install rust

cargo install flavours

## Add cargo bin dir to PATH
ln -s ../share/cargo/bin/ ~/.local/bin/cargo
## Assumes...
## Make reloading idempotent
# [[ -z "$PATH_ORIGINAL" ]] && export PATH_ORIGINAL=$PATH || export PATH=$PATH_ORIGINAL
## Adds `~/.local/bin` (and all subdirs) to $PATH
# export PATH="${$(find -L ~/.local/bin -type d -print0 | xargs -0n1 -I {} zsh -c 'printf %q: {}')%%:}:$PATH"


flavours update all

## Add zsh completions
[[ -d $COMPLETIONS_DIRECTORY ]] || COMPLETIONS_DIRECTORY="${fpath[1]}"
git clone https://github.com/Misterio77/flavours "$SRC_DIRECTORY/flavours"
ln -s "$SRC_DIRECTORY/flavours/completions/zsh" "$COMPLETIONS_DIRECTORY/_flavours"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants