<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1246766347711307622</atom:id><lastBuildDate>Wed, 04 Jan 2012 05:47:51 +0000</lastBuildDate><category>productivity</category><category>tools</category><title>Amol Jadhav</title><description /><link>http://amol-jadhav.blogspot.com/</link><managingEditor>noreply@blogger.com (Amol Jadhav)</managingEditor><generator>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AmolJadhav" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="amoljadhav" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1246766347711307622.post-4602002420621468749</guid><pubDate>Thu, 04 Jun 2009 03:41:00 +0000</pubDate><atom:updated>2012-01-03T21:47:51.601-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">tools</category><category domain="http://www.blogger.com/atom/ns#">productivity</category><title>Grep within eclipse</title><description>Searching has become a common activity at all scopes right from the internet search to the search within a folder. Eclipse supports searching and it also have a Google Desktop search plug-in which highlights the search term within the resource like this.&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_TKIwOdgZl54/SidPdNnfDeI/AAAAAAAACEg/6F7FZipvcmk/s1600-h/highlight.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 272px; height: 27px;" src="http://1.bp.blogspot.com/_TKIwOdgZl54/SidPdNnfDeI/AAAAAAAACEg/6F7FZipvcmk/s320/highlight.png" alt="" id="BLOGGER_PHOTO_ID_5343326846188457442" border="0" /&gt;&lt;/a&gt;And it shows me the search result like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_TKIwOdgZl54/SidQiX5yDqI/AAAAAAAACEo/7nS5LtvsvFY/s1600-h/searchResult.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 410px; height: 138px;" src="http://1.bp.blogspot.com/_TKIwOdgZl54/SidQiX5yDqI/AAAAAAAACEo/7nS5LtvsvFY/s320/searchResult.jpg" alt="" id="BLOGGER_PHOTO_ID_5343328034360528546" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Well, this is okay but this makes me to have several clicks to expand the folders/files to find the specific file or line for which I made the search. More often I'm interested in the how the search term is being used in the code files and don't want to expand collapse huge package structure to find it. This reminds me grep, a Unix utility which perfect for my need. I'm a huge fan of Unix utilities. Grep is simple; it gives me exactly what I want in very simple one line result. Following is the part of result for search term "socket".&lt;br style="font-family: lucida grande;"&gt;&lt;span style="font-family: courier new;"&gt;&lt;br /&gt;&lt;br /&gt;Module.java:19:SocketConnector connector = new SocketConnector();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;Builder.java:20:    socketConnector.setPort(8080);&lt;/span&gt;&lt;br /&gt;....&lt;br /&gt;&lt;br /&gt;No need to navigate if &lt;span style="font-family: courier new;"&gt;Module.java&lt;/span&gt; and &lt;span style="font-family: courier new;"&gt;Builder.java&lt;/span&gt; if they were in different packages.&lt;br /&gt;&lt;br /&gt;But running grep needs me to switch context by opening a command window and navigating to my project location, even worse if I want to grep within a package then I will have to know the location of the package within project and type in few more characters. Context switching is bad, it steals my concentration.&lt;br /&gt;&lt;br /&gt;What I did was simple trick but it made my life easier. I configured grep as an external tool for eclipse. Here is how:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Open External tool configuration dialog box (Ctrl-E)&lt;/li&gt;&lt;li&gt;Click "new launch configuration"&lt;/li&gt;&lt;li&gt;Specify the location of grep in Location text box&lt;/li&gt;&lt;li&gt;Give working directory as &lt;span style="font-family: courier new;"&gt;${resource_loc}&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: courier new;"&gt;&lt;span style="font-family: georgia;"&gt;Give arguments as &lt;/span&gt;"--mmap --exclude-dir=.* -i -I -s -r -n ${string_prompt} *.*"&lt;span style="font-family: georgia;"&gt; (exclude quotes)&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: courier new;"&gt;&lt;span style="font-family: georgia;"&gt;Name it as grep (or whatever you want)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family: courier new;"&gt;&lt;span style="font-family: georgia;"&gt;Now click on a folder/project/package in which you want to search and run grep external tool eclipse will prompt you for a text put your search term in it and console tab will be filled up with the grep result! Bingo!&lt;br /&gt;&lt;br /&gt;Now, lets look at the two ${xx}. This is a variable whose value is filled by the eclipse. &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: georgia;"&gt;&lt;span style="font-family: courier new;"&gt;${resource_loc}&lt;/span&gt; is the location of the currently selected resource. &lt;span style="font-family: courier new;"&gt;${string_prompt}&lt;/span&gt; is filled by prompting user for a string input. The &lt;span style="font-family: courier new;"&gt;${resource_loc}&lt;/span&gt; is good since I can have more granular search, within package, folder, project. This is much better than eclipse search, since to do this it requires you to touch mouse and check some radio buttons. If you always want to search within a specific location then specify respective location as working directory for the grep.&lt;br /&gt;&lt;br /&gt;I have specified several &lt;/span&gt;&lt;span style="font-family: courier new;"&gt;&lt;/span&gt;arguments to grep, semantically it means that recursively search the directories [-r], exclude directories which starts with the "." chars [--exclude-dir=.*] (this is because I wanted to skip files within ".svn" directory), case insensitive search [-i], put line numbers of the file [-n], exclude binary files [-I] (.class, for example), and use memory mapped IO if possible [--mmap], this improves performance.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246766347711307622-4602002420621468749?l=amol-jadhav.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://amol-jadhav.blogspot.com/2009/06/grep-within-eclipse.html</link><author>noreply@blogger.com (Amol Jadhav)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/_TKIwOdgZl54/SidPdNnfDeI/AAAAAAAACEg/6F7FZipvcmk/s72-c/highlight.png" height="72" width="72" /><thr:total>0</thr:total></item></channel></rss>

