Return to Snippet

Revision: 19179
at October 16, 2009 22:16 by phalkunz

Initial Code
# Search text in files under the current folder
# by Saophalkun Ponlu
# 15 Jun 2009 | Last Changed 12 Oct 2009

# input dialog box
res=$(CocoaDialog inputbox --title "Search Folder" \
--informative-text "Enter a search string:" \
--button1 "Okay" --button2 "Cancel")

# get the actual search string
SEARCH=$(tail -n1 <<<"$res")

# search and replace regular expression
REPLACE='<li><a href=\"txmt:\/\/open\/?url=file:\/\/\/\1\&line=\2\">\1 (\2)<\/a> <p>\3<\/p><\/li>'

# output styles
echo "
body { font-size: 12px; }
li { list-style: none; border-bottom: 2px solid #eee; padding: 10px 5px 5px }
li p { color: #333; margin-left: 1.5em; margin-top: .6em; margin-bottom: 1.2em; }


# if the selected item (path) is a file then get its directory instead
if [ -f "$SELECTED_DIR" ]; then

echo "<h3>You searched for: <em style=\"color: red\">$SEARCH</em></h3>"

# the search process starts
grep -rn --exclude=*.svn-base "$SEARCH" $SELECTED_DIR | sed  "s/$MATCH/$REPLACE/g"

Initial URL

Initial Description
This is a script for finding a string in files under a current folder in TextMate. It can be very convenient if you know what you are looking is in a particular folder by saving your time searching each file individually or going through a long list of the search result produced by ‘Find in Project’ function.

Improved version of

Initial Title
TextMate: Search a Current Folder

Initial Tags

Initial Language