mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Add search commands to the gitx cli
-s or --search= for searching in subject, author or SHA -S or --Search= for git's pickaxe string matching -r or --regex= for git's pickaxe regex matching
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -173,6 +173,23 @@
|
||||
</parameter>
|
||||
</command>
|
||||
|
||||
<command name="search" code="GitXSrch" description="Highlight commits that match the given search string.">
|
||||
<direct-parameter type="specifier" description="The repository document to search."/>
|
||||
<parameter name="string" code="SRCH" type="text" optional="yes" description="The string to search for.">
|
||||
<cocoa key="searchString"/>
|
||||
</parameter>
|
||||
<parameter name="in mode" code="Mode" type="integer" optional="yes" description="The type of search (defalts to basic [Subject, Author, SHA]).">
|
||||
<cocoa key="inMode"/>
|
||||
</parameter>
|
||||
</command>
|
||||
|
||||
<class-extension extends="document" code="docu" description="A document.">
|
||||
<cocoa class="PBGitRepository"/>
|
||||
<responds-to name="search">
|
||||
<cocoa method="findInModeScriptCommand:"/>
|
||||
</responds-to>
|
||||
</class-extension>
|
||||
|
||||
</suite>
|
||||
|
||||
</dictionary>
|
||||
|
||||
@@ -12,4 +12,7 @@
|
||||
#define kGitXAEKeyArgumentsList 'ARGS'
|
||||
|
||||
#define kGitXCloneDestinationURLKey @"destinationURL"
|
||||
#define kGitXCloneIsBareKey @"isBare"
|
||||
#define kGitXCloneIsBareKey @"isBare"
|
||||
|
||||
#define kGitXFindSearchStringKey @"searchString"
|
||||
#define kGitXFindInModeKey @"inMode"
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
|
||||
- (IBAction) fetchPullPushAction:(id)sender;
|
||||
|
||||
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
|
||||
|
||||
@property(readonly) NSMutableArray *items;
|
||||
@property(readonly) NSView *sourceListControlsView;
|
||||
@end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -47,4 +47,7 @@
|
||||
- (IBAction) openInTerminal:(id)sender;
|
||||
- (IBAction) cloneTo:(id)sender;
|
||||
- (IBAction) refresh:(id)sender;
|
||||
|
||||
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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 -
|
||||
|
||||
@@ -60,4 +60,6 @@ typedef enum historySearchModes {
|
||||
- (void)clearSearch;
|
||||
- (IBAction)updateSearch:(id)sender;
|
||||
|
||||
- (void)setHistorySearch:(NSString *)searchString mode:(NSInteger)mode;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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(" <branch> select specific branch or tag\n");
|
||||
printf(" -- <path(s)> show commits touching paths\n");
|
||||
printf(" -S<string> show commits that introduce or remove an instance of <string>\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<string>, --search=<string>\n");
|
||||
printf(" search for string in Subject, Author or SHA\n");
|
||||
printf(" -S<string>, --Search=<string>\n");
|
||||
printf(" commits that introduce or remove an instance of <string>\n");
|
||||
printf(" -r<regex>, --regex=<regex>\n");
|
||||
printf(" commits that introduce or remove strings that match <regex>\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
|
||||
|
||||
Reference in New Issue
Block a user