expand cd tab autocomplete

This commit is contained in:
Yan Lin 2026-01-21 17:10:09 +01:00
parent 2a1db299c8
commit 7cba60f231

View file

@ -79,7 +79,6 @@
bindkey -M viins '^[[65;2u' self-insert
# Disable expand-or-complete on potential problematic keys in vim insert mode
bindkey -M viins '^I' expand-or-complete # Keep tab completion but be explicit
# Configure autosuggestions to not interfere with vim mode
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(vi-add-eol)
@ -117,6 +116,23 @@
else
"thunar \"$current_dir\" &"}
}
# Custom cd completion with fzf (only for empty cd command)
function _fzf_cd_complete() {
local tokens=(''${(z)LBUFFER})
if [[ ''${tokens[1]} == "cd" && -z ''${tokens[2]} ]]; then
local selected
selected=$(fd --type d --max-depth 1 . "$PWD" 2>/dev/null | fzf --height 40% --preview 'ls -la {}' --header="Select directory")
if [[ -n "$selected" ]]; then
LBUFFER="cd $selected"
fi
zle redisplay
else
zle expand-or-complete
fi
}
zle -N _fzf_cd_complete
bindkey '^I' _fzf_cd_complete
'';
};