views:

180

answers:

3

Let assume that we have this output in bash console:

$ findgrep RAILS_ENV                                   
./script/munin_stats:7:RAILS_ENV = ENV['RAILS_ENV'] || "development"
./script/munin_stats:12:    dbconfig = dbhash[RAILS_ENV]            
./lib/tasks/juggernaut.rake:4:    @rails_env = ENV["RAILS_ENV"] || "development"                             
./lib/tasks/cruise.rake:19:    ENV['RAILS_ENV'] = 'test'                                                     
./lib/tasks/populate.rake:15:      dumper = MysqlDumper.new(ActiveRecord::Base.configurations[RAILS_ENV])    
./lib/tasks/populate.rake:21:      dumper = MysqlDumper.new(ActiveRecord::Base.configurations[RAILS_ENV])    
./lib/tasks/populate.rake:29:      RAILS_ENV = "test"

How to create on file name (for example './script/munin_stats:7') clickable link (for example Ctrl+click) which will open selected file in my favourite editor?

A: 

Hotwire can do this.

Michael Foukarakis
+1  A: 

This is more a function of the terminal emulator (e.g., xterm or gnome-terminal) than bash. The popular urxvt terminal emulator (e.g. apt-get install rxvt-unicode) is extensible in Perl so it should be possible to write a urxvt filter to take a selection and execute an editor based on the selection.

The default 'selection-popup' script (see Perl source here) already recognizes when you have a file:number pattern selected and offers the option to transform that into a vi command that will open the file at the right line.

Emil
A: 

If you don't mind using GUI to display the list you can try zenity:

vi `findgrep RAILS_ENV * | cut -f 1 -d : |  zenity --list --column Files`

NB: it could be useful if you reveal the terminal emulator you (prefer to) use.

Jack