ianthehenry / sd

a cozy nest for your scripts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not getting completions in zsh

ckp95 opened this issue · comments

commented

Not sure if I'm just overlooking something really obvious but I don't get any tab completions.

Test sd dir with these contents:

$ echo $SD_ROOT 
/home/cameron/me/dotfiles/scripts/sd-root
$ tree sd-root 
sd-root
└── test-cmd
    ├── bar
    └── foo
$ cat sd-root/test-cmd/foo 
#!/usr/bin/env bash

set -euo pipefail

# this is the foo command docstring
echo "this is the foo command"
$ cat sd-root/test-cmd/bar
#!/usr/bin/env bash

set -euo pipefail

# this is the bar command docstring
echo "this is the bar command"

When I do sd test-cmd foo it runs the script as I expect, and when I do sd test-cmd --help it prints this like it should:

$ sd test-cmd --help
test-cmd commands

bar -- this is the bar command docstring
foo -- this is the foo command docstring

However, I'm not getting the appropriate tab completion like the readme says I should:

sd test-cmd <TAB>
# (this instead lists the contents of the current working directory)

I stripped my zshrc down to the bare minimum that still runs sd and exhibits the problem:

#!/usr/bin/zsh

zstyle :compinstall filename '/home/cameron/.zshrc'
autoload -Uz compinit
compinit

source "$HOME/me/dotfiles/aliases"
export PATH="$SCRIPTS:$PATH" # $SCRIPTS is from aliases file; sd executable is symlinked in here

# sd stuff
fpath=("$HOME/me/dotfiles/src/sd" "${fpath[@]}")
export SD_ROOT="$HOME/me/dotfiles/scripts/sd-root"

The dotfiles/src/sd directory is where I have the repository cloned to. I have closed and restarted the shell to make sure the fpath gets loaded, and I've verified that it is indeed on the fpath:

$ echo $fpath | tr " " "\n"
/usr/lib/kitty/shell-integration/zsh/completions
/home/cameron/me/dotfiles/src/sd
/usr/local/share/zsh/site-functions
/usr/share/zsh/site-functions
/usr/share/zsh/functions/Calendar
/usr/share/zsh/functions/Chpwd
/usr/share/zsh/functions/Completion
/usr/share/zsh/functions/Completion/Base
/usr/share/zsh/functions/Completion/Linux
/usr/share/zsh/functions/Completion/Unix
/usr/share/zsh/functions/Completion/X
/usr/share/zsh/functions/Completion/Zsh
/usr/share/zsh/functions/Exceptions
/usr/share/zsh/functions/Math
/usr/share/zsh/functions/MIME
/usr/share/zsh/functions/Misc
/usr/share/zsh/functions/Newuser
/usr/share/zsh/functions/Prompts
/usr/share/zsh/functions/TCP
/usr/share/zsh/functions/VCS_Info
/usr/share/zsh/functions/VCS_Info/Backends
/usr/share/zsh/functions/Zftp
/usr/share/zsh/functions/Zle

$ cd /home/cameron/me/dotfiles/src/sd
$ ls
sdefaults  _sd  LICENSE  README.md  sd  sd.plugin.zsh

So, any idea what to do?

(Thanks for this tool btw, it's really comfy to use, despite this one little problem)

EDIT: I also tried defining the SD_ROOT variable first and then editing the fpath in case the order mattered somehow:

export SD_ROOT="$HOME/me/dotfiles/scripts/sd-root"
fpath=("$HOME/me/dotfiles/src/sd" "${fpath[@]}")

but that didn't fix it.

Ah! I think I might know the problem. I think you need to set fpath before you call compinit. Alternately I think you can call rehash after setting fpath to fix it.

Let me know if this actually is the issue and I'll add a note to the README about this, because that's extremely subtle.

commented

Thanks, setting the fpath before compinit was what worked (rehash didn't).

Oh good! Sorry for the incorrect installation instructions. I've updated the README with this.