Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [feature] Provide a pkg-config file



Le 14/07/2023 à 19:34, Wu Zhenyu a écrit :
bash-completion has a pkg-config file, developers who want to provide completions can get the directory by

I recently had the same problem of determining where to install the completion function for my program.

Here's what I did, should this be useful to anyone. I'd be happy to hear if there is a better solution.

Note: I believe I read somewhere that /usr/share/zsh/site-functions is always in fpath so forcing the user to install it there could be an option.

Note2: For my personal use, this made me add ~/.local/share/zsh/site-functions to my fpath and I realized that another program had just assumed that this was the directory for completions and put its there and I was missing out on it.

Makefile
```
...
ZSH_FUNCTIONS_DIR=$(PREFIX)/share/zsh/site-functions

install:
	...
	install -Dm644 "$(SRC_DIR)/_tss.zsh" "$(ZSH_FUNCTIONS_DIR)/_tss"
	# (tss is the name of my program)
	zsh postinstall.zsh "$(ZSH_FUNCTIONS_DIR)"
```

postinstall.zsh
```
...
local functions_dir=$1
if ! ((fpath[(Ie)$functions_dir])); then
	cat <<EOF
###
###  ${(qqq)functions_dir} doesn't seem to be in your
### fpath, at least in non-interactive mode. You need to add it, which ### you can do by running:
###
### print -r ${(qq):-fpath+=(${(qqq)functions_dir})} >>${(q-)ZDOTDIR:-$HOME}/.zshenv
###
EOF
fi
```

--
Johan





Messages sorted by: Reverse Date, Date, Thread, Author