diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-02-06 12:29:56 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-02-06 12:29:56 +0000 |
commit | 80e609859d582b518b29735ad5314a687ee10abb (patch) | |
tree | b810cea8846a74f9f919d80fb608fafedd4deac1 /Source/CMTextView.m | |
parent | cc40f75fbe1896eb69d84a8f00ed20b6bb70bd28 (diff) | |
download | sequelpro-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
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r-- | Source/CMTextView.m | 57 |
1 files changed, 57 insertions, 0 deletions
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 |