Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a shell extension that allows me to do filename completion similarly to Command-T.

Command-T a feature in TextMate and a plugin for Vim that allows you to select filenames by typing portions of them which need not be contiguous. It uses a ranking system to decide which filename to use, and provides a menu of available options. If you're not familiar with this feature the best way to understand it is to watch the first video from the command-t home page.

What tool can I use so that I can have Command-T-style completion for filenames in my shell? (Bash currently, open to alternatives.)

share|improve this question

4 Answers 4

up vote 1 down vote accepted

Zsh to the rescue!

Toss the following into your ~/.zshrc file and enjoy!

Please note, it may not be nearly as good as TM's ability to find file names but it's leaps and bounds better than the default autocomplete found in bash.

##############################################################
# Stuff from http://zshwiki.org/home/examples/compquickstart #
##############################################################
zmodload zsh/complist
autoload -U compinit && compinit
zstyle ':completion:::::' completer _complete _approximate
zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX + $#SUFFIX) / 3 )) )'
zstyle ':completion:*:descriptions' format "- %d -"
zstyle ':completion:*:corrections' format "- %d - (errors %e})"
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*' menu select
zstyle ':completion:*' verbose yes
## case-insensitive (uppercase from lowercase) completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
#zstyle ':completion:*' special-dirs ..
share|improve this answer
    
This is the solution I've ended up going with, although it is definitely nowhere near as good as Command-T. –  Ryan Patterson Feb 26 '12 at 4:44

Here's how I added Command-T/CtrlP fuzzy completion to my ZShell:

Step 1: Install matcher.

Step 2: Add the following to your ~/.zshrc:

_matcher_complete() {
  integer i=1
  (git ls-files 2>/dev/null || find .) | /usr/local/bin/matcher --limit 20 ${words[CURRENT]} | while read line; do
    compadd -U -2 -V $i -- "$line"
    i=$((i+1))
  done
  compstate[insert]=menu
}

zle -C matcher-complete complete-word _generic
zstyle ':completion:matcher-complete:*' completer _matcher_complete
zstyle ':completion:matcher-complete:*' menu-select

bindkey '^X^T' matcher-complete

Step 3: Enter a string to fuzzy-find, type CTRL+xt, and enjoy:

Terminal Demo.

share|improve this answer

The name of what Cmd+T does in TextMate is "fuzzy matching" (and variants).

Googling these terms associated with bash returns this script and a related question on Stackoverflow.

Looks like I've found a new toy!

share|improve this answer

You may want to check out fzf, a general purpose fuzzy finder for any shell.

Its install script will add CTRL-T key binding to your shell, which works pretty much like Command-T.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.