From: Simon Ruderich Date: Sun, 16 Mar 2014 17:31:41 +0000 (+0100) Subject: zsh/rc: tab on empty input lists all files in the directory X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=9b3e741610ff2fbc754a5700e3e4cb0962670e61;p=config%2Fdotfiles.git zsh/rc: tab on empty input lists all files in the directory --- diff --git a/zsh/rc b/zsh/rc index b6c359c..201e17c 100644 --- a/zsh/rc +++ b/zsh/rc @@ -635,10 +635,26 @@ autoload -Uz compinit && compinit -d ~/.zsh/cache/zcompdump zstyle ':completion:*' use-cache yes zstyle ':completion:*' cache-path ~/.zsh/cache +# List all files in the current directory when pressing tab on an empty input, +# behave like complete-word otherwise. Thanks to John Eikenberry [1] for the +# code, read on 2014-03-15. +# +# [1]: http://unix.stackexchange.com/a/32426 +complete-word-or-complete-list-of-files() { + if [[ $#BUFFER == 0 ]]; then + BUFFER='ls ' + CURSOR=3 + zle list-choices + zle backward-kill-word + else + zle complete-word + fi +} +zle -N complete-word-or-complete-list-of-files # Let the completion system handle all completions, including expanding of # shell wildcards (which is handled by other shell mechanisms if the default # expand-or-complete is used). -bindkey '^I' complete-word +bindkey '^I' complete-word-or-complete-list-of-files # If there are multiple matches after pressing always display them # immediately without requiring another . a completes to aa and # lists aaa, aab, aac as possible completions if the directory contains aaa,