diff --git a/modules/zsh.nix b/modules/zsh.nix index f0d1bf1..ec97fe5 100644 --- a/modules/zsh.nix +++ b/modules/zsh.nix @@ -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 ''; };