Skip to content

Instantly share code, notes, and snippets.

@michaelgold
Created September 6, 2017 15:17
Show Gist options
  • Save michaelgold/b902552ec19ea123cfb088c1def58342 to your computer and use it in GitHub Desktop.
Save michaelgold/b902552ec19ea123cfb088c1def58342 to your computer and use it in GitHub Desktop.
Taskwarrior Windows 10 Wrapper for Ubuntu Bash
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Forked from https://bitbucket.org/kvorobyev/taskwarriorc2/issues/32/wrapper-for-task-install-in-windows
// Compile in bash with the command: x86_64-w64-mingw32-gcc task.c -o task.exe
char* concat(const char *s1, const char *s2)
{
char *result = malloc(strlen(s1)+strlen(s2)+1);
strcpy(result, s1);
strcat(result, s2);
return result;
}
int main(int argc , char * argv[]) {
char * prefix = "c:/windows/system32/bash.exe -c \"task ";
char * postfix = " \"";
char * old_buffer;
char * argbuffer = "";
for (int i=1 ; i < argc ; i++) {
argbuffer = concat(argbuffer, " \'");
argbuffer = concat(argbuffer, argv[i]);
argbuffer = concat(argbuffer, "\'");
argbuffer = concat(argbuffer, " ");
}
char * cmdbuffer = malloc (strlen(prefix) + strlen(argbuffer) + strlen(postfix)+1);
sprintf(cmdbuffer, "%s%s%s", prefix, argbuffer, postfix);
return system(cmdbuffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment