From: "ara.t.howard" Date: 2007-11-18T12:17:11+09:00 Subject: Re: Readline + completion of "all files in current directory" On Nov 17, 2007, at 8:50 AM, Marc Heiler wrote: > I am having a hard time understanding readline. If i have a list of > possible matches for given files (and subdirectories) in a directory, > how can I make readline work with that, so that i can type something > like: > > some_method r > > where some_method would be just a method, and "r" a file in current > directory (ie. rx.rb ry.rb rz.rb files) > > Readline.completion_proc = proc do |word| > Dir['*'].grep(/\A#{Regexp.quote(word)}/) > end > Readline.completion_case_fold = true > # hmm cfp:~ > cat a.rb require 'readline' class File def self.tab arg, prompt = 'directory > ' candidates = Array === arg ? candidates : Dir[arg] Readline.completion_proc = lambda do |abbrev| list = candidates.select{|candidate| candidate.index(abbrev) == 0} list = list.empty? ? candidates : list end Readline.readline prompt end end p File.tab('*').strip cfp:~ > ruby a.rb directory > s sane_transactions.rb sfctmp.rb site spadoc_watch src sudo sciruby sif_nighttime_drop source sqlite.sh ss.png svn directory > si sif_nighttime_drop site directory > site "site" a @ http://codeforpeople.com/ -- it is not enough to be compassionate. you must act. h.h. the 14th dalai lama