From 0134c738cc55668ade593b3420e582be88ce3462 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 6 Aug 2019 15:37:08 +0200 Subject: zshrc: Add fzf hosts completion Signed-off-by: Florian Pritz --- .zshrc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.zshrc b/.zshrc index ac97d9b..ab08cc3 100644 --- a/.zshrc +++ b/.zshrc @@ -265,11 +265,29 @@ fzf-file-widget() { return $ret } +__fhost() { + printf "%s\n" $hosts | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | while read item; do + echo -n "${(q)item} " + done + local ret=$? + echo + return $ret +} + +fzf-hosts-widget() { + LBUFFER="${LBUFFER}$(__fhost)" + local ret=$? + zle reset-prompt + return $ret +} + if type fzf &>/dev/null; then zle -N fzf-history-widget bindkey '^R' fzf-history-widget zle -N fzf-file-widget bindkey '^T' fzf-file-widget + zle -N fzf-hosts-widget + bindkey '^H' fzf-hosts-widget fi # }}} @@ -709,6 +727,7 @@ hosts=( $_ssh_config_hosts[@] localhost ) +hosts=(${(u)hosts[@]}) zstyle ':completion:*:hosts' hosts $hosts # automagic url quoter -- cgit v1.2.3-24-g4f1b