public
Description: A SIMBL plugin for Terminal.app which enable us to copy on selection.
Homepage: http://blog.s21g.com/articles/1075
Clone URL: git://github.com/genki/terminalcopyonselect.git
terminalcopyonselect / TerminalCopyOnSelect.m
100644 32 lines (28 sloc) 0.956 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#import <objc/runtime.h>
#import "TerminalCopyOnSelect.h"
#import "TCOSPreferences.h"
 
@implementation NSObject (TerminalCopyOnSelect)
- (void)
myMouseUp:(NSEvent *)theEvent
{
[self myMouseUp:theEvent];
if(![[NSUserDefaults standardUserDefaults] boolForKey:USER_DEFAULTS_KEY]) return;
NSString *selectedText = [[(id)self performSelector:@selector(selectedText)] retain];
if([selectedText length] > 0){
[(id)self performSelector:@selector(copy:) withObject:nil];
}
[selectedText release];
}
@end
 
@implementation TerminalCopyOnSelect
+(void) load
{
// allocate and initialize the preferences which load the user defaults
[TCOSPreferences sharedInstance];
 
Class class = objc_getClass("TTView");
Method mouseUp = class_getInstanceMethod(class, @selector(mouseUp:));
Method myMouseUp = class_getInstanceMethod(class, @selector(myMouseUp:));
method_exchangeImplementations(mouseUp, myMouseUp);
 
NSLog(@"TerminalCopyOnSelect installed");
}
@end