Shell – zsh tab completion on empty line

configurationshellzsh

I'd like a tcsh'ism that I haven't been able to find: On a blank line with no content, I want to press the tab key and see the equivalent of an ls. That is to say I want

$ <tab>

to do something other then giving me a \t. I've found fantastic resources for command completion, but not for this base case. Any help on this would be great! Thanks.

Best Answer

# expand-or-complete-or-list-files
function expand-or-complete-or-list-files() {
    if [[ $#BUFFER == 0 ]]; then
        BUFFER="ls "
        CURSOR=3
        zle list-choices
        zle backward-kill-word
    else
        zle expand-or-complete
    fi
}
zle -N expand-or-complete-or-list-files
# bind to tab
bindkey '^I' expand-or-complete-or-list-files