Search code examples
regexag

Regex with Silver Searcher in Tmux + ZSH falis


I'm trying to ag results through a pipe using a regular expression but it is not working.

~/c/octoly git:1470 ❯❯❯ drake routes | ag pro_store --page=less -r                                                                                                                                        
Running via Spring preloader in process 9140
                                   pro_store_stores_users POST                /pro/stores/:store_id/stores_users(.:format)                                 pro/stores_users#create
                                new_pro_store_stores_user GET                 /pro/stores/:store_id/stores_users/new(.:format)                             pro/stores_users#new
                               edit_pro_store_stores_user GET                 /pro/stores/:store_id/stores_users/:id/edit(.:format)                        pro/stores_users#edit
~/c/octoly git:1470 ❯❯❯ drake routes | ag '^pro_store' --page=less -r                                                                                                                                     
Running via Spring preloader in process 8669
~/c/octoly git:1470 ❯❯❯ drake routes | ag ^pro_store --page=less -r                                                                                                                                       
Running via Spring preloader in process 8743
rake aborted!
Errno::EPIPE: Broken pipe @ io_write - /dev/ttys010
/Users/adrien/.gem/ruby/2.2.4/gems/railties-4.2.6/lib/rails/tasks/routes.rake:6:in `write'
/Users/adrien/.gem/ruby/2.2.4/gems/railties-4.2.6/lib/rails/tasks/routes.rake:6:in `puts'
/Users/adrien/.gem/ruby/2.2.4/gems/railties-4.2.6/lib/rails/tasks/routes.rake:6:in `puts'
/Users/adrien/.gem/ruby/2.2.4/gems/railties-4.2.6/lib/rails/tasks/routes.rake:6:in `block in <top (required)>'
/Users/adrien/.gem/ruby/2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
/Users/adrien/.gem/ruby/2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `block in load'
/Users/adrien/.gem/ruby/2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/adrien/.gem/ruby/2.2.4/gems/activesupport-4.2.6/lib/active_support/dependencies.rb:268:in `load'
-e:1:in `<main>'
Tasks: TOP => routes
(See full trace by running task with --trace)

I am trying to get results starting with pro_store. I've read the broken pipe could be because of the ag stuff ending before the drake stuff but I don't get how and why if that's really what's happening.


Solution

  • Try with drake routes | ag "^ *pro_store" --page=less -r

    Your output doesn't "start" with pro_store, but multiple spaces and then pro_store. That's why the [:space:]* addition to your regex.