After long hiatus, there’s a new version of the File Search plugin for Gedit. However, the only visible change is that results are now sorted. Most changes have happened under the hood meanwhile, by reorganizing the search implementation. Hopefully this will allow for some more goodies in the future (Progress bar? Integration with some Project Manager plugin?); but for now I’m glad that this change is done.
So please give it a try, and if you notice anything weird about it, please leave a comment! I’m especially interested to hear if there’s any visible slowdown due to sorting… Theoretically it should be slower, but in practice it shouldn’t be noticeable.
Btw. many thanks for your feedback so far! It’s really good to see how the plugin is used “in the wild”, and I’m planning to get lots of the ideas and comments into the next version – hopefully without such a long delay this time :-)
August 24, 2009 at 9:11 pm
Any chance we get it to work on os x now that gedit has been ported? It starts up fine but never returns from a search.
Thanks for an awesome plugin by the way, it was the last missing piece to making gedit the ultimate editor for me.
August 24, 2009 at 10:52 pm
Didn’t know there’s a Mac port of Gedit! Getting the search plugin working there would be cool!
Technically, there might be some difference in the OS X versions of grep or find commands, or in the shell. I don’t have access to such a system; maybe we get the plugin working if you or someone else is willing to put some debugging into it.
To start, here are two commands that the plugin uses; if you execute these in the Terminal, what is the output?
find $HOME -xtype f -print
grep -H -I -n -s -Z -F -e ‘abc’ ~/somefile
(replace “somefile” with the name of a text file in your home directory).
Sorry for the vague description; I’m not familiar with OS X :-( .
September 17, 2009 at 5:46 pm
find $HOME -xtype f -print doesn’t recognize xtype
find $HOME -type f -print lists all the files in $HOME with full path
grep -H -I -n -s -Z -F -e ‘abc’ ~/somefile returns nothing, the quotes confused grep
grep -H -I -n -s -Z -F -e abc ~/somefile returns
/Users/triathlon/somefile10: abcdefg
I can help with debugging.
September 17, 2009 at 6:10 pm
thought it might be the xtype thing so I changed it in the code, then I got the following message when running via command line
find: !: nothing between ! and -o
I uncommented a print line in RunCommand and got the following:
executing command: ['find', '/Users/triathlon/work/www3/', '(', '!', '-path', '/Users/triathlon/work/www3/*/.*', ')', '(', '!', '-path', '/Users/triathlon/work/www3/.*', ')', '(', '!', '-name', '*~', '!', '-name', '.#*.*', ')', '(', '!', '-path', '*/CVS/*', '!', '-path', '*/.svn/*', '!', '-path', '*/.git/*', '!', '-path', '*/RCS/*', ')', '(', '-false', '-o', '-name', '*.js', '-o', '-name', '*.py', '-o', '-name', '*.html', ')', '-type', 'f', '-print']
September 17, 2009 at 6:16 pm
thought it might be the -name parameters so I removed all file types from the dialog and got this:
executing command: ['find', '/Users/triathlon/work/www3/', '-type', 'f', '-print']
No error this time, it just hangs. Tried cancelling via the stop button and then I get:
OSError: [Errno 2] No such file or directory: ‘/proc’
Out of my depth now, let me know if you want me to try something else.
September 17, 2009 at 6:28 pm
Wow, thanks for the info! I’ll try to put together a version that has some of these problems fixed and that gives better debug output; should be ready in a few minutes.
For now, http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/find.1.html confirms that -xtype is not supported – not sure if there’s a good replacement, or maybe -type is fine in this case.
The “/proc” directory is indeed missing on Mac OS X, but maybe this functionality isn’t even necessary any more (it was used for killing the Find and Grep processes, but I think that can be done differently now).
Note sure about the “find: !: nothing between ! and -o” problem or the hanging Find command; better debug output should help.
September 17, 2009 at 7:08 pm
Here’s a file-search.py file with some more debug output and hopefully fixed Cancel button (actually I think the Cancel thing was broken on Linux as well after the latest changes):
http://github.com/oliver/gedit-file-search/raw/macport/file-search.py
There’s a new “macport” branch at http://github.com/oliver/gedit-file-search/tree/macport now where these changes will be collected.
The problem with -name parameter is probably still in this version, but the simple Find command should give better debug output now.
September 17, 2009 at 9:17 pm
Tried it out. The -o error has gone when I specify file types but find still does not return (with file types or not). “ps aux | grep find” returns
triathlon 7616 0.0 0.0 0 0 s001 Z+ 9:12PM 0:00.00 (find)
pushing “stop” prints out the following:
(cancelling command)
main pid: 7616; num procs: 1
killing pid 7616
but ps aux has the process still running forever, doesn’t disappear until I quit gedit.
October 5, 2009 at 1:36 am
Congratulations, I like this plugin, itś very useful and helped me in very many taks. I write a post about File Search in Portuguese and I left my recommendations. I hope the guys here in Brazil can use this tool in their projects.
Thank very much!!
Hug.
October 5, 2009 at 2:49 am
[...] gostou do plugin deixe um comentário para o autor, pois é legal copiar e mais legal ainda é reconhecer os [...]
October 7, 2009 at 1:28 am
[...] gostou do plugin File Search deixe um comentário para o autor, pois é legal copiar e mais legal ainda é reconhecer os [...]
October 11, 2009 at 6:37 pm
get_uri() return a quoted uri.
but need unquoted searchDir.
file-search.py commit :59888c1
721c721
searchDir = urllib.unquote(os.path.dirname(currFileDir[7:]))
Wish the info above could help. May be the test suit’ path should contain non-ascii character,
Thanks for your great plugin!
October 11, 2009 at 7:29 pm
soiamso: thanks for finding this bug and posting a solution! It’s already commited: http://github.com/oliver/gedit-file-search/commit/ab7f2b406e1e1e1152be01863b94dd6535880cf9
October 20, 2009 at 2:56 pm
Cool plugin. Simple and easy to use.
thanks-
November 3, 2009 at 10:23 pm
Pretty good, it is very fast and seems to find everything.
Thanks for putting it up for us to download
My only suggestion, in the search results – add “Contract All” and “Expand All” somewhere so when i get 60 files, i dont have to manually do it to each to look through file names only
December 11, 2009 at 10:02 am
Finally a Find in Files plugin that works! :)
Thanks a lot for this.
December 14, 2009 at 8:08 pm
Great plugin, it works and is fast. Just a suggestion: is it possibile to persist plugin in the bottom of the gui ? i like di hide and maybe review the last search easily.
December 15, 2009 at 6:35 pm
F: currently all search results remain in the bottom panel until you click the Close button in a tab. If the bottom panel is hidden you can show it with Ctrl+F9. Could you clarify your suggestion?
Thanks, Oliver
February 6, 2010 at 7:38 pm
thanks! plugin very useful!
When out the “search and replace in directories” plugin?
February 9, 2010 at 2:39 pm
mandrillo, nice to hear you like the plugin :-)
Unfortunately I currently don’t have much time to work on it. So I don’t think I can add search-and-replace functionality soon; sorry.
March 11, 2010 at 6:28 am
Hi
Thanks for the great plugin.
I made a small change , added a whole word (on|off) functionality.
If you think it is worth publishing I can send it to you.
BR
March 11, 2010 at 7:23 pm
strandjata, that functionality sounds very useful; and it would be nice if you could send it to me at olivergerlich at gmxde. However, I currently don’t have much time to work on the plugin, but maybe I can find some time to add your changes.
March 12, 2010 at 3:04 pm
I sent it this morning at the mail from the git logs , it has dot between your first and surname right ?
March 12, 2010 at 6:20 pm
Thanks for the mail; I’ve just noticed that WordPress has removed some parts of my address but you figured it out correctly :-) I don’t have full email access at the moment and couldn’t reply. Will have a look at your changes when I’m back.
April 15, 2010 at 9:53 am
Thanks a lot.
Exactly what I needed !!!!
Would it be possible to put all this files in a a directory in order to keep a .gnome2/gedit/plugins well organized ?
April 22, 2010 at 3:16 pm
Thank you so much for this!
I had pretty much given up on finding it and was resigning myself to having to create a whole plugin for it. So thank you for saving me so much time!
May 18, 2010 at 12:34 pm
Really great plugin for programming, thank you very much.
JUst have two suggestions for it, perhaps one is even easier to solve:
- add this plugin under the CTRL+F key combination; perhaps it is possible already
- add search in new tab; checkbox that a new tab should be oppened with the results of the new search and a small list to reuse the existing search tabs
May 18, 2010 at 1:04 pm
Nice to hear you like the plugin :-)
Regarding your suggestions:
- currently the search dialog can be opened with Ctrl+Shift+F key combo; Ctrl+F is already used for normal Search
- such a feature might be useful, but I don’t quite like the thought of adding even more options to the search dialog. I’ll have to think about this.
July 13, 2010 at 1:22 pm
love the plugin!
July 13, 2010 at 1:24 pm
love it
July 17, 2010 at 8:59 pm
Great ! I’ve been searching it for years, your plugin is the only one that REALLY works !
Thanks a lot :-)
July 29, 2010 at 8:27 pm
Thanks a ton for your efforts on this. Has saved me lots of time. Great job!
September 8, 2010 at 1:21 pm
Hi Oliver,
Here’s a patch that adds highlighting of what you’ve searched and whole word searching. If there is a better way of sending you patches, please let me know.
———————————–
diff –git a/file-search.glade b/file-search.glade
index d2b5ffa..5599020 100644
— a/file-search.glade
+++ b/file-search.glade
@@ -75,6 +75,17 @@
True
True
+
+
+
+ True
+ True
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+ Whole word
+ 0
+ True
+ True
+
False
diff –git a/file-search.py b/file-search.py
index 0fa71e9..96982d9 100644
— a/file-search.py
+++ b/file-search.py
@@ -178,6 +178,7 @@ class SearchQuery:
self.text = ”
self.directory = ”
self.caseSensitive = True
+ self.wholeWord = True;
self.isRegExp = False
self.includeSubfolders = True
self.excludeHidden = True
@@ -197,6 +198,11 @@ class SearchQuery:
self.caseSensitive = True
try:
+ self.wholeWord = gclient.get_without_default(gconfBase+”/whole_word”).get_bool()
+ except:
+ self.wholeWord = True
+
+ try:
self.isRegExp = gclient.get_without_default(gconfBase+”/is_reg_exp”).get_bool()
except:
self.isRegExp = False
@@ -228,6 +234,7 @@ class SearchQuery:
def storeDefaults (self, gclient):
gclient.set_bool(gconfBase+”/case_sensitive”, self.caseSensitive)
+ gclient.set_bool(gconfBase+”/whole_word”, self.wholeWord)
gclient.set_bool(gconfBase+”/is_reg_exp”, self.isRegExp)
gclient.set_bool(gconfBase+”/include_subfolders”, self.includeSubfolders)
gclient.set_bool(gconfBase+”/exclude_hidden”, self.excludeHidden)
@@ -388,6 +395,8 @@ class GrepProcess:
grepCmd += ["-i"]
if not(self.query.isRegExp):
grepCmd += ["-F"]
+ if (self.query.wholeWord):
+ grepCmd += ["-w"]
# Assume all file contents are in UTF-8 encoding (AFAIK grep will just search for byte sequences, it doesn’t care about encodings):
self.queryText = self.queryText.encode(“utf-8″)
@@ -773,6 +782,7 @@ class FileSearchWindowHelper:
query = SearchQuery()
query.loadDefaults(self.gclient)
self.tree.get_widget(‘cbCaseSensitive’).set_active(query.caseSensitive)
+ self.tree.get_widget(‘cbWholeWord’).set_active(query.wholeWord)
self.tree.get_widget(‘cbRegExp’).set_active(query.isRegExp)
self.tree.get_widget(‘cbIncludeSubfolders’).set_active(query.includeSubfolders)
self.tree.get_widget(‘cbExcludeHidden’).set_active(query.excludeHidden)
@@ -810,6 +820,7 @@ class FileSearchWindowHelper:
query.text = searchText
query.directory = searchDir
query.caseSensitive = self.tree.get_widget(‘cbCaseSensitive’).get_active()
+ query.wholeWord = self.tree.get_widget(‘cbWholeWord’).get_active();
query.isRegExp = self.tree.get_widget(‘cbRegExp’).get_active()
query.includeSubfolders = self.tree.get_widget(‘cbIncludeSubfolders’).get_active()
query.excludeHidden = self.tree.get_widget(‘cbExcludeHidden’).get_active()
@@ -996,11 +1007,9 @@ class FileSearcher:
if lineno > 0: # this is necessary for Gedit 2.17.4 and older (see gbo #401219)
currDoc = self._window.get_active_document()
currDoc.goto_line(lineno – 1) # -1 required to work around gbo #503665
- currView = gedit.tab_get_from_document(currDoc).get_view()
- currView.scroll_to_cursor()
# workaround to scroll to cursor position when opening file into window of “Unnamed Document”:
- gobject.idle_add(scrollToCursorCb, currView)
+ gobject.idle_add(scrollToCursorCb, self)
def on_btnClose_clicked (self, button):
self.destroy()
@@ -1058,8 +1067,19 @@ class FileSearcher:
clipboard.store()
-def scrollToCursorCb (view):
- view.scroll_to_cursor()
+def scrollToCursorCb (searcher):
+ currDoc = searcher._window.get_active_document()
+ currView = gedit.tab_get_from_document(currDoc).get_view()
+ currView.scroll_to_cursor()
+
+ flags = 0
+
+ if searcher.query.caseSensitive:
+ flags = 2
+ if searcher.query.wholeWord:
+ flags = flags + 1
+
+ currDoc.set_search_text(searcher.query.text, flags)
return False
def resultSearchCb (model, column, key, it):
September 8, 2010 at 1:26 pm
Looks like it didn’t like the glade file. I’ll modify the xml tags here and try once more. You can replace ~ with > and ` with < to get back to the patch.
———————————————–
diff –git a/file-search.glade b/file-search.glade
index d2b5ffa..5599020 100644
— a/file-search.glade
+++ b/file-search.glade
@@ -75,6 +75,17 @@
`property name="active"~True`/property~
`property name="draw_indicator"~True`/property~
`/widget~
+ `/child~
+ `child~
+ `widget class="GtkCheckButton" id="cbWholeWord"~
+ `property name="visible"~True`/property~
+ `property name="can_focus"~True`/property~
+ `property name="events"~GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK`/property~
+ `property name="label" translatable="yes"~Whole word`/property~
+ `property name="response_id"~0`/property~
+ `property name="active"~True`/property~
+ `property name="draw_indicator"~True`/property~
+ `/widget~
`packing~
`property name="expand"~False`/property~
`/packing~
diff –git a/file-search.py b/file-search.py
index 0fa71e9..96982d9 100644
— a/file-search.py
+++ b/file-search.py
@@ -178,6 +178,7 @@ class SearchQuery:
self.text = ''
self.directory = ''
self.caseSensitive = True
+ self.wholeWord = True;
self.isRegExp = False
self.includeSubfolders = True
self.excludeHidden = True
@@ -197,6 +198,11 @@ class SearchQuery:
self.caseSensitive = True
try:
+ self.wholeWord = gclient.get_without_default(gconfBase+"/whole_word").get_bool()
+ except:
+ self.wholeWord = True
+
+ try:
self.isRegExp = gclient.get_without_default(gconfBase+"/is_reg_exp").get_bool()
except:
self.isRegExp = False
@@ -228,6 +234,7 @@ class SearchQuery:
def storeDefaults (self, gclient):
gclient.set_bool(gconfBase+"/case_sensitive", self.caseSensitive)
+ gclient.set_bool(gconfBase+"/whole_word", self.wholeWord)
gclient.set_bool(gconfBase+"/is_reg_exp", self.isRegExp)
gclient.set_bool(gconfBase+"/include_subfolders", self.includeSubfolders)
gclient.set_bool(gconfBase+"/exclude_hidden", self.excludeHidden)
@@ -388,6 +395,8 @@ class GrepProcess:
grepCmd += ["-i"]
if not(self.query.isRegExp):
grepCmd += ["-F"]
+ if (self.query.wholeWord):
+ grepCmd += ["-w"]
# Assume all file contents are in UTF-8 encoding (AFAIK grep will just search for byte sequences, it doesn't care about encodings):
self.queryText = self.queryText.encode("utf-8")
@@ -773,6 +782,7 @@ class FileSearchWindowHelper:
query = SearchQuery()
query.loadDefaults(self.gclient)
self.tree.get_widget('cbCaseSensitive').set_active(query.caseSensitive)
+ self.tree.get_widget('cbWholeWord').set_active(query.wholeWord)
self.tree.get_widget('cbRegExp').set_active(query.isRegExp)
self.tree.get_widget('cbIncludeSubfolders').set_active(query.includeSubfolders)
self.tree.get_widget('cbExcludeHidden').set_active(query.excludeHidden)
@@ -810,6 +820,7 @@ class FileSearchWindowHelper:
query.text = searchText
query.directory = searchDir
query.caseSensitive = self.tree.get_widget('cbCaseSensitive').get_active()
+ query.wholeWord = self.tree.get_widget('cbWholeWord').get_active();
query.isRegExp = self.tree.get_widget('cbRegExp').get_active()
query.includeSubfolders = self.tree.get_widget('cbIncludeSubfolders').get_active()
query.excludeHidden = self.tree.get_widget('cbExcludeHidden').get_active()
@@ -996,11 +1007,9 @@ class FileSearcher:
if lineno ~ 0: # this is necessary for Gedit 2.17.4 and older (see gbo #401219)
currDoc = self._window.get_active_document()
currDoc.goto_line(lineno – 1) # -1 required to work around gbo #503665
- currView = gedit.tab_get_from_document(currDoc).get_view()
- currView.scroll_to_cursor()
# workaround to scroll to cursor position when opening file into window of "Unnamed Document":
- gobject.idle_add(scrollToCursorCb, currView)
+ gobject.idle_add(scrollToCursorCb, self)
def on_btnClose_clicked (self, button):
self.destroy()
@@ -1058,8 +1067,19 @@ class FileSearcher:
clipboard.store()
-def scrollToCursorCb (view):
- view.scroll_to_cursor()
+def scrollToCursorCb (searcher):
+ currDoc = searcher._window.get_active_document()
+ currView = gedit.tab_get_from_document(currDoc).get_view()
+ currView.scroll_to_cursor()
+
+ flags = 0
+
+ if searcher.query.caseSensitive:
+ flags = 2
+ if searcher.query.wholeWord:
+ flags = flags + 1
+
+ currDoc.set_search_text(searcher.query.text, flags)
return False
def resultSearchCb (model, column, key, it):
October 11, 2010 at 4:14 pm
Great plugin. Do you have a paypal donate link?
January 3, 2011 at 4:44 pm
Great plugin. simpel and functional
January 21, 2011 at 1:04 am
hi! thanks for this plugin! will this work in Ubuntu 10.04? please i would like to know. need this one. thanks!
January 30, 2011 at 6:19 pm
Rob, sorry for the long delay, and thanks for your patch! I have just published a change that offers the whole-word option which Strandjata and you have both proposed, though it is now implemented in a different way to avoid the peculiarities of grep. I’d be glad if you could give it a test!
January 30, 2011 at 6:21 pm
Alan: nope, no paypal link available as this is a pure hobby project and I don’t want no pressure :-)
Brando: the plugin works fine in Ubuntu 10.04 for me. If you encounter problems, please tell me!
February 4, 2011 at 8:54 am
hey Oliver,
Much love mate, I’m using file search all the time and have made a couple of small formatting modifications at pastebin.com/LddZcB8R
Would you consider a collapse all /expand all button?
Sometimes I don’t care for the contents and only want to see in which files strings occur. if one file includes 100′s of instances it kind of blows out the results view size
February 4, 2011 at 8:53 pm
Andy, the Expand All/Collapse All feature is now available in the development version (eg. at http://github.com/oliver/gedit-file-search/raw/master/file-search.py).
The changed colors you proposed were difficult to use in my default bright Gnome/Gedit theme; but I suppose if you use a dark theme the current colors are not very useful either :-)
I’m not sure yet how to handle this – ideally the plugin would use the system-wide color for the yellow markers and some other system-wide color instead of blue result lines. But apparently it’s not that easy to get the values of these system colors.
February 14, 2011 at 5:04 pm
Excellent tool, very useful, simple and well done.
February 18, 2011 at 5:58 pm
Is there a way that I can search files that have been mounted with SSH for instance. I am able to edit them within gedit but I want to search through them the bookmark does not show up.
February 20, 2011 at 11:46 am
Andrew: searching remote folders is currently not enabled as it would require to transfer the content of all searched files over SSH. In my tests, this was very slow.
However, you can give it a try yourself:
- click Ctrl-Shift-F to open the File Search dialog
- click Browse
- navigate to your home directory
- right-click in the right-side pane and select Show Hidden Files
- go into the .gvfs folder in your home directory
- there you find all remote directories (SSH etc) and can browse them as usual, and select one for searching
Besides the slow performance, I’m not sure whether this feature would actually work on all systems (the user would have to have the gvfs-fuse-daemon running, which is not guaranteed).
Still, I’d be interested in feedback whether this is actually a useful feature despite the performance.
February 21, 2011 at 6:38 pm
Oliver,
After some testing this weekend the proposed solution works well. I tried on multiple connections. Searching for the same term on each connection to get an idea of the time it takes. The slowest connection I tried was a 1/meg download 256k/upload as expected it took the longest at 5min. The same search on the local box was nearly instantaneous. I tried on a 10meg link as well and the search took less than a minute. I also tried on a gigabit network and the search was very very quick. So it would be a neat option to be able to enable but the work around is fine for now.