开发者

How to parse links in bash output

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?


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.


Hotwire can do this.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜