My friend hacked up a ruby script to enable some better use of the bash command line. The problem I was having was that sometimes I wanted the bash command line to be interactive so that could pick one of several outputs. For instance let's say I am hunting for a file to edit from bash
so I run:
jalvarado:~/bobo jalvarado$ find . -name "Have*"
Well, the second file is the one I want to edit so to get to in the normal bash may I may have to write.
vi `find . -name "Have*" | head -n 2 | tail -n 1`
and that would open the second file, but that is alot of typing and if I then wanted to open a different file of that set I would have to modify the command line in two places. So he wrote a script that let's you use this type of syntax
jalvarado:~/bobo jalvarado$ choose vi `find . -name "Have*"`
Then you type "2" and up comes your file. Even better would be syntax like
find . -name "Have*" | choose vi
but haven't figured that one out yet.
Here is the Ruby script.
if ((ARGV.nil?) || (ARGV.size <> filename1 filename2 ...';
puts 'example: choose "cvs log" `find . -iname "*tokenizer.java*"`';
command = ARGV;
filenames = ARGV[1,ARGV.size];
filenames.each_with_index do | line, index |
puts '[' + (index+1).to_s + '] ' + line
selection = STDIN.readline
filename = filenames[selection.to_i-1]
Open3.popen3(command + " " + filename) do |read_stdin, read_stdout, read_stderr|