Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Text Editor Filename Completion



On Mar 11,  1:10pm, Peter Stephenson wrote:
} Subject: Re: Text Editor Filename Completion
}
} > Does anyone have any completion commands set up for vi or emacs that
} > give preference to plain text files -- those containing source code --
} 
} zstyle ':completion:*:*:(emacs|vi):*' file-patterns \
}     '*.(c|h|pl|tex|txt):globbed-files *(-/):directories' '*:all-files'

How about this:

  textfiles() {
    reply=( ${${(@M)${(f)"$(file $REPLY 2>/dev/null)"}\:#*text*}%:*} )
  }
  zstyle ':completion:*:*:(emacs|vi|vim):*' file-patterns \
    '%p(e,textfiles,):globbed-files *(-/):directories' '*:all-files' 

(I found that I needed the "|vim" in there because vi is aliased to vim
on my system and the alias is expanded before the completion context is
established [unless you setopt completealiases]).



Messages sorted by: Reverse Date, Date, Thread, Author