aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-02-06 12:29:56 +0000
committerBibiko <bibiko@eva.mpg.de>2010-02-06 12:29:56 +0000
commit80e609859d582b518b29735ad5314a687ee10abb (patch)
treeb810cea8846a74f9f919d80fb608fafedd4deac1
parentcc40f75fbe1896eb69d84a8f00ed20b6bb70bd28 (diff)
downloadsequelpro-80e609859d582b518b29735ad5314a687ee10abb.tar.gz
sequelpro-80e609859d582b518b29735ad5314a687ee10abb.tar.bz2
sequelpro-80e609859d582b518b29735ad5314a687ee10abb.zip
• further preparations to allow to run any bash command(s) incl. any scripts like Perl, Ruby, AppleScript etc inside the text macro snippets of the query favorites and insert the result for such a bash command as snippet à la:
SELECT ${1:$(cat ~/Desktop/foo.txt)} or ${1:$(open 'http://www.sequelpro.com')} - such a task can be interrupted by pressing ⌘ + . anytime - if the task doesn't exit successfully the error will be written into the the standard Console log - not yet activate
-rw-r--r--Source/CMTextView.h2
-rw-r--r--Source/CMTextView.m57
2 files changed, 59 insertions, 0 deletions
diff --git a/Source/CMTextView.h b/Source/CMTextView.h
index a7c0ccea..c278c2c3 100644
--- a/Source/CMTextView.h
+++ b/Source/CMTextView.h
@@ -139,4 +139,6 @@ static inline id NSMutableAttributedStringAttributeAtIndex (NSMutableAttributedS
- (BOOL)isSnippetMode;
+- (NSString *)runBashCommand:(NSString *)command;
+
@end
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 33d56544..37b2ee13 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -1260,6 +1260,63 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
}
/*
+ * Run 'command' as BASH script and return the result.
+ * This task can be interrupted by pressing ⌘.
+ */
+- (NSString *)runBashCommand:(NSString *)command
+{
+
+ NSTask *bashTask = [[NSTask alloc] init];
+ [bashTask setLaunchPath: @"/bin/sh"];
+
+ NSArray *arguments;
+ arguments = [NSArray arrayWithObjects: @"-c", command, nil];
+ [bashTask setArguments: arguments];
+
+ NSPipe *pipe;
+ pipe = [NSPipe pipe];
+ [bashTask setStandardOutput: pipe];
+
+ NSFileHandle *file;
+ file = [pipe fileHandleForReading];
+
+ [bashTask launch];
+ while([bashTask isRunning]) {
+ NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
+ untilDate:[NSDate distantFuture]
+ inMode:NSDefaultRunLoopMode
+ dequeue:YES];
+ if(!event) continue;
+ if ([event type] == NSKeyDown) {
+ unichar key = [[event characters] length] == 1 ? [[event characters] characterAtIndex:0] : 0;
+ if (([event modifierFlags] & NSCommandKeyMask) && key == '.') {
+ [bashTask terminate];
+ break;
+ }
+ }
+ usleep(10000);
+ }
+ [bashTask waitUntilExit];
+ NSInteger status = [bashTask terminationStatus];
+ NSData *data;
+ data = [file readDataToEndOfFile];
+
+ NSString *string;
+ string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
+ [bashTask release];
+
+ if (status == 0) {
+ return [string autorelease];
+ } else {
+ NSLog(@"Error: %@", string);
+ [string autorelease];
+ NSBeep();
+ return @"";
+ }
+
+
+}
+/*
* Checks whether the current caret position in inside of a defined snippet range
*/
- (BOOL)checkForCaretInsideSnippet