diff --git a/GitX.h b/GitX.h
index 7825b7f..a07c4b7 100644
--- a/GitX.h
+++ b/GitX.h
@@ -43,6 +43,7 @@
- (void) delete; // Delete an object.
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
- (void) moveTo:(SBObject *)to; // Move an object to a new location.
+- (void) searchString:(NSString *)string inMode:(NSInteger)inMode; // Highlight commits that match the given search string.
@end
@@ -66,6 +67,18 @@
- (void) delete; // Delete an object.
- (void) duplicateTo:(SBObject *)to withProperties:(NSDictionary *)withProperties; // Copy an object.
- (void) moveTo:(SBObject *)to; // Move an object to a new location.
+- (void) searchString:(NSString *)string inMode:(NSInteger)inMode; // Highlight commits that match the given search string.
+
+@end
+
+
+
+/*
+ * GitX Suite
+ */
+
+// A document.
+@interface GitXDocument (GitXSuite)
@end
diff --git a/GitX.sdef b/GitX.sdef
index db0348d..55a6d04 100644
--- a/GitX.sdef
+++ b/GitX.sdef
@@ -173,6 +173,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/GitXScriptingConstants.h b/GitXScriptingConstants.h
index 7a786a4..4f04f5b 100644
--- a/GitXScriptingConstants.h
+++ b/GitXScriptingConstants.h
@@ -12,4 +12,7 @@
#define kGitXAEKeyArgumentsList 'ARGS'
#define kGitXCloneDestinationURLKey @"destinationURL"
-#define kGitXCloneIsBareKey @"isBare"
\ No newline at end of file
+#define kGitXCloneIsBareKey @"isBare"
+
+#define kGitXFindSearchStringKey @"searchString"
+#define kGitXFindInModeKey @"inMode"
diff --git a/PBGitRepository.h b/PBGitRepository.h
index 86b094a..7599c6c 100644
--- a/PBGitRepository.h
+++ b/PBGitRepository.h
@@ -125,6 +125,10 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
- (void) setup;
- (void) forceUpdateRevisions;
+// for the scripting bridge
+- (void)findInModeScriptCommand:(NSScriptCommand *)command;
+
+
@property (assign) BOOL hasChanged;
@property (readonly) PBGitWindowController *windowController;
@property (readonly) PBGitConfig *config;
diff --git a/PBGitRepository.m b/PBGitRepository.m
index 48a70f4..9d7862c 100644
--- a/PBGitRepository.m
+++ b/PBGitRepository.m
@@ -19,6 +19,7 @@
#import "PBGitRevList.h"
#import "PBGitDefaults.h"
#import "GitXScriptingConstants.h"
+#import "PBHistorySearchController.h"
NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
@@ -1008,6 +1009,19 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
[super showWindows];
}
+// for the scripting bridge
+- (void)findInModeScriptCommand:(NSScriptCommand *)command
+{
+ NSDictionary *arguments = [command arguments];
+ NSString *searchString = [arguments objectForKey:kGitXFindSearchStringKey];
+ if (searchString) {
+ NSInteger mode = [[arguments objectForKey:kGitXFindInModeKey] integerValue];
+ [PBGitDefaults setShowStageView:NO];
+ [self.windowController showHistoryView:self];
+ [self.windowController setHistorySearch:searchString mode:mode];
+ }
+}
+
#pragma mark low level
diff --git a/PBGitSidebarController.h b/PBGitSidebarController.h
index ba4dd2f..e2f712f 100644
--- a/PBGitSidebarController.h
+++ b/PBGitSidebarController.h
@@ -38,6 +38,8 @@
- (IBAction) fetchPullPushAction:(id)sender;
+- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
+
@property(readonly) NSMutableArray *items;
@property(readonly) NSView *sourceListControlsView;
@end
diff --git a/PBGitSidebarController.m b/PBGitSidebarController.m
index 03167bd..efcf6f1 100644
--- a/PBGitSidebarController.m
+++ b/PBGitSidebarController.m
@@ -15,6 +15,7 @@
#import "NSOutlineViewExt.h"
#import "PBAddRemoteSheet.h"
#import "PBGitDefaults.h"
+#import "PBHistorySearchController.h"
@interface PBGitSidebarController ()
@@ -184,6 +185,11 @@
[sourceView reloadData];
}
+- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode
+{
+ [historyViewController.searchController setHistorySearch:searchString mode:mode];
+}
+
#pragma mark NSOutlineView delegate methods
- (void)outlineViewSelectionDidChange:(NSNotification *)notification
diff --git a/PBGitWindowController.h b/PBGitWindowController.h
index 1d9cac8..29f5245 100644
--- a/PBGitWindowController.h
+++ b/PBGitWindowController.h
@@ -47,4 +47,7 @@
- (IBAction) openInTerminal:(id)sender;
- (IBAction) cloneTo:(id)sender;
- (IBAction) refresh:(id)sender;
+
+- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
+
@end
diff --git a/PBGitWindowController.m b/PBGitWindowController.m
index 8df3139..1968c48 100644
--- a/PBGitWindowController.m
+++ b/PBGitWindowController.m
@@ -191,6 +191,11 @@
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
+- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode
+{
+ [sidebarController setHistorySearch:searchString mode:mode];
+}
+
#pragma mark -
diff --git a/PBHistorySearchController.h b/PBHistorySearchController.h
index e51ba47..c3e6459 100644
--- a/PBHistorySearchController.h
+++ b/PBHistorySearchController.h
@@ -60,4 +60,6 @@ typedef enum historySearchModes {
- (void)clearSearch;
- (IBAction)updateSearch:(id)sender;
+- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
+
@end
diff --git a/PBHistorySearchController.m b/PBHistorySearchController.m
index 8a48320..2281da9 100644
--- a/PBHistorySearchController.m
+++ b/PBHistorySearchController.m
@@ -110,6 +110,16 @@
[self startBackgroundSearch];
}
+- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode
+{
+ if (searchString && ![searchString isEqualToString:@""]) {
+ self.searchMode = mode;
+ [searchField setStringValue:searchString];
+ // use performClick: so that the search field will save it as a recent search
+ [searchField performClick:self];
+ }
+}
+
- (void)awakeFromNib
{
[self setupSearchMenuTemplate];
diff --git a/gitx.m b/gitx.m
index ecb9a6f..f213977 100644
--- a/gitx.m
+++ b/gitx.m
@@ -10,6 +10,7 @@
#import "PBEasyPipe.h"
#import "GitXScriptingConstants.h"
#import "GitX.h"
+#import "PBHistorySearchController.h"
@@ -53,7 +54,6 @@ void usage(char const *programName)
printf("\n");
printf(" select specific branch or tag\n");
printf(" -- show commits touching paths\n");
- printf(" -S show commits that introduce or remove an instance of \n");
printf("\n");
printf("Diff options\n");
printf(" See 'man git-diff' for options you can pass to gitx --diff\n");
@@ -63,6 +63,15 @@ void usage(char const *programName)
printf(" git diff [options] | gitx\n");
printf(" use gitx to pipe diff output to a GitX window\n");
printf("\n");
+ printf("Search\n");
+ printf("\n");
+ printf(" -s, --search=\n");
+ printf(" search for string in Subject, Author or SHA\n");
+ printf(" -S, --Search=\n");
+ printf(" commits that introduce or remove an instance of \n");
+ printf(" -r, --regex=\n");
+ printf(" commits that introduce or remove strings that match \n");
+ printf("\n");
printf("Creating repositories\n");
printf(" These commands will create a git repository and then open it up in GitX\n");
printf("\n");
@@ -199,6 +208,74 @@ void handleClone(NSURL *repositoryURL, NSMutableArray *arguments)
exit(0);
}
+#define kShortBasicSearch @"-s"
+#define kBasicSearch @"--search="
+#define kShortPickaxeSearch @"-S"
+#define kPickaxeSearch @"--Search="
+#define kShortRegexSearch @"-r"
+#define kRegexSearch @"--regex="
+
+NSArray *commandLineSearchPrefixes()
+{
+ return [NSArray arrayWithObjects:kShortBasicSearch, kBasicSearch, kShortPickaxeSearch, kPickaxeSearch, kShortRegexSearch, kRegexSearch, nil];
+}
+
+PBHistorySearchMode searchModeForCommandLineArgument(NSString *argument)
+{
+ if ([argument hasPrefix:kShortBasicSearch] || [argument hasPrefix:kBasicSearch])
+ return kGitXBasicSeachMode;
+
+ if ([argument hasPrefix:kShortPickaxeSearch] || [argument hasPrefix:kPickaxeSearch])
+ return kGitXPickaxeSearchMode;
+
+ if ([argument hasPrefix:kShortRegexSearch] || [argument hasPrefix:kRegexSearch])
+ return kGitXRegexSearchMode;
+
+ return 0;
+}
+
+GitXDocument *documentForURL(SBElementArray *documents, NSURL *URL)
+{
+ NSString *path = [URL path];
+
+ for (GitXDocument *document in documents) {
+ NSString *documentPath = [[document file] path];
+ if ([[documentPath lastPathComponent] isEqualToString:@".git"])
+ documentPath = [documentPath stringByDeletingLastPathComponent];
+
+ if ([documentPath isEqualToString:path])
+ return document;
+ }
+
+ return nil;
+}
+
+void handleGitXSearch(NSURL *repositoryURL, NSMutableArray *arguments)
+{
+ NSString *searchString = [arguments componentsJoinedByString:@" "];
+ NSInteger mode = searchModeForCommandLineArgument(searchString);
+
+ // remove the prefix from search string before sending it
+ NSArray *prefixes = commandLineSearchPrefixes();
+ for (NSString *prefix in prefixes)
+ if ([searchString hasPrefix:prefix]) {
+ searchString = [searchString substringFromIndex:[prefix length]];
+ break;
+ }
+
+ if ([searchString isEqualToString:@""])
+ exit(0);
+
+ GitXApplication *gitXApp = [SBApplication applicationWithBundleIdentifier:kGitXBundleIdentifier];
+ [gitXApp open:[NSArray arrayWithObject:repositoryURL]];
+
+ // need to find the document after opening it
+ GitXDocument *repositoryDocument = documentForURL([gitXApp documents], repositoryURL);
+ [repositoryDocument searchString:searchString inMode:mode];
+
+ exit(0);
+}
+
#pragma mark -
#pragma mark main
@@ -287,6 +364,10 @@ int main(int argc, const char** argv)
[arguments removeObjectAtIndex:0];
handleClone(wdURL, arguments);
}
+
+ if (searchModeForCommandLineArgument(firstArgument)) {
+ handleGitXSearch(wdURL, arguments);
+ }
}
// No commands handled by gitx, open the current dir in GitX with the arguments