zsh: Add fzf-tab manpage preview for commands

If a command has a manpage associated, we now display it in the
fzf-preview box that fzf-tab completion shows.
This commit is contained in:
Marty Oehme 2025-12-10 09:32:14 +01:00
parent 4b720464ff
commit b6e84bbc99
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -94,8 +94,11 @@ zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
# show systemd unit status
zstyle ':fzf-tab:complete:systemctl-*:*' fzf-preview 'SYSTEMD_COLORS=1 systemctl status $word'
# env var contents
zstyle ':fzf-tab:complete:(-command-|-parameter-|-brace-parameter-|export|unset|expand):*' \
zstyle ':fzf-tab:complete:(-parameter-|-brace-parameter-|export|unset|expand):*' \
fzf-preview 'echo ${(P)word}'
# give MAN pages for cmds or show their expanded path
zstyle ':fzf-tab:complete:-command-:*' fzf-preview \
'(out=$(tldr --color always "$word") 2>/dev/null && echo $out) || (out=$(MANWIDTH=$FZF_PREVIEW_COLUMNS man "$word") 2>/dev/null && echo $out) || (out=$(which "$word") && echo $out) || echo "${(P)word}"'
# show hostname if we are in a distrobox environment
if [ -n "$DISTROBOX_ENTER_PATH" ] && [ -f /run/.containerenv ]; then