4

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 github 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.)

2

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 ..
| 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
1

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

| improve this answer | |
0

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!

| improve this answer | |
0

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.

| improve this answer | |
0

fish is an alternative shell that supports partial path autocomplete

For example cd /v/l/fsck Tab will convert the path to /var/log/fsck/. cd /u/s/appl Tab will expand the path to /usr/share/applications/.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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