the all-thing | 2010-09-06 17:55:10 -0400 ========================================== ruby readline filename tab completion ------------------------------------- Date: July 10, 2008 2:55pm Author: William Morgan Labels: ruby URL: http://all-thing.net/ruby-readline-tab-completion.txt Navigating the ancient Readline interface is a bit complicated. Here's how to get filename completion when you hit the tab button: require 'readline' def ask_for_filename question, start_dir="" Readline.completion_append_character = nil Readline.completion_proc = lambda do |prefix| files = Dir["#{start_dir}#{prefix}*"] files. map { |f| File.expand_path(f) }. map { |f| File.directory?(f) ? f + "/" : f } end Readline.readline question end Replies -------- William Morgan, on March 6, 2009 8:51am: ["| Also you can do something like:\n", "| \n", "| \n", "| Readline::HISTORY.push answer\n", "| \n", "| to store the answer in the edit history. Unfortunately that\n", "| doesn't return @answer@ so you invariably end up with a k-combinator-type\n", "| situation. But if you're using readline in the first place, you've probably\n", "| already realized it ain't gonna be pretty.\n", "| \n"] William Morgan, on March 6, 2009 1:51pm: ["| Also you can do something like:\n", "| \n", "| \n", "| Readline::HISTORY.push answer\n", "| \n", "| to store the answer in the edit history. Unfortunately that\n", "| doesn't return @answer@ so you invariably end up with a k-combinator-type\n", "| situation. But if you're using readline in the first place, you've probably\n", "| already realized it ain't gonna be pretty.\n", "| \n"] This delicious text version served up by Whisper .