-
-
Save yury/7a99c559e7b687a861b2f40cba67bbc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int pbcopy(int argc, char** argv) { | |
if (argc == 1) { | |
// no arguments, listen to stdin | |
if (currentSession == NULL) { | |
currentSession = [[sessionParameters alloc] init]; | |
} | |
const int bufsize = 1024; | |
char buffer[bufsize]; | |
NSMutableData* data = [[NSMutableData alloc] init]; | |
ssize_t count = 0; | |
while ((count = read(fileno(thread_stdin), buffer, bufsize-1))) { | |
[data appendBytes:buffer length:count]; | |
} | |
NSString* result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; | |
if (!result) { | |
return 1; | |
} | |
[UIPasteboard generalPasteboard].string = result; | |
} else { | |
// threre are arguments, concatenate and paste: | |
char* cmd = concatenateArgv(argv + 1); | |
[UIPasteboard generalPasteboard].string = @(cmd); | |
free(cmd); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment