]> ruderich.org/simon Gitweb - config/dotfiles.git/blobdiff - zsh/rc
zsh/rc: tab on empty input lists all files in the directory
[config/dotfiles.git] / zsh / rc
diff --git a/zsh/rc b/zsh/rc
index ece0a2d67bacbf5fcbaa254578c8dfc9de4fa2ae..201e17c13a5ed103ffdb67e65c9e9b03e53430ea 100644 (file)
--- a/zsh/rc
+++ b/zsh/rc
@@ -528,11 +528,17 @@ if [[ $TERM == screen* || $TERM == xterm* || $TERM == rxvt* ]]; then
                 program_name=git
                 ;;
             m)
-                program_name=mutt
+                program_name=make
+                ;;
+            p)
+                program_name=less
                 ;;
             v)
                 program_name=vim
                 ;;
+            mu)
+                program_name=mutt
+                ;;
         esac
 
         # Add an exclamation mark at the beginning if running with sudo or if
@@ -629,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 <Tab> always display them
 # immediately without requiring another <Tab>. a<Tab> completes to aa and
 # lists aaa, aab, aac as possible completions if the directory contains aaa,