How to parse links in bash outputs

Suppose we have this output in the 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 a file name (for example, "./ script / munin_stats: 7") a clickable link (for example, Ctrl + click) that will open the selected file in my favorite editor?

+3
source share
3 answers

This depends more on the terminal emulator (e.g. xterm or gnome-terminal) than bash. A popular urxvt terminal emulator (for example, apt-get install rxvt-unicode) extends in Perl, so it should be possible to write a urxvt filter for selection and run a selection-based editor.

" " script (. Perl ) , : vi, .

+1
0

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

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

Note: this can be useful if you find a terminal emulator that you (prefer) to use.

0
source

Source: https://habr.com/ru/post/1720058/


All Articles