task

creates a plain-text task file in the current directory
git clone git://brookjeynes.dev/bjeynes/task.git
Log | Files | Refs | README | LICENSE

commit b60c0f6cbf8446b2c3d1710adb3fce8caa53ef6b
parent 9c1ba05da7e23ac3c9c02ed3b9e9e7722acdcefc
Author: brookjeynes <me@brookjeynes.dev>
Date:   Thu, 11 Jun 2026 16:44:01 +1000

feat: better handle positional arguments

Diffstat:
Mmain.c | 47++++++++++++++++++++++++++++++++---------------
1 file changed, 32 insertions(+), 15 deletions(-)

diff --git a/main.c b/main.c @@ -6,12 +6,11 @@ struct options { char *title; - char *properties; char priority; }; static void print_help(const char *program) { - printf("usage: %s [--priority A|-p A] <title> [properties]\n", program); + printf("usage: %s [--priority A|-p A] <title> [properties...]\n", program); printf("\n"); printf("create a new task.\n"); printf("\n"); @@ -35,7 +34,7 @@ int main(int argc, char *argv[]) { exit(1); } - int positional = 0; + int positionals = 0; for (int idx = 1; idx < argc; idx++) { if (strcmp(argv[idx], "--priority") == 0 || strcmp(argv[idx], "-p") == 0) { if (cli_args.priority != '\0') { @@ -69,16 +68,11 @@ int main(int argc, char *argv[]) { exit(1); } - if (positional == 0) { + if (positionals == 0) { cli_args.title = argv[idx]; - } else if (positional == 1) { - cli_args.properties = argv[idx]; - } else { - fprintf(stderr, "err: too many arguments\n"); - exit(1); } - positional++; + positionals++; } if (cli_args.title == NULL) { @@ -135,8 +129,19 @@ int main(int argc, char *argv[]) { } } - if (cli_args.properties != NULL) { - if (fprintf(f, " %s", cli_args.properties) < 0) { + int seen_title = 0; + for (int idx = 1; idx < argc; idx++) { + if (strcmp(argv[idx], "--priority") == 0 || strcmp(argv[idx], "-p") == 0) { + idx++; + continue; + } + + seen_title++; + if (seen_title == 1) { + continue; + } + + if (fprintf(f, " %s", argv[idx]) < 0) { if (!write_failed) { write_failed = 1; write_errno = errno; @@ -168,13 +173,25 @@ int main(int argc, char *argv[]) { exit(1); } - char *editor = getenv("EDITOR"); + char *editor = getenv("VISUAL"); + if (editor != NULL && strcmp(editor, "") == 0) { + editor = NULL; + } + + if (editor == NULL) { + editor = getenv("EDITOR"); + } + + if (editor != NULL && strcmp(editor, "") == 0) { + editor = NULL; + } + if (editor == NULL) { return 0; } - char *args[] = {editor, title_to_file, NULL}; - execvp(editor, args); + execlp("sh", "sh", "-c", "exec $1 \"$2\"", "task", editor, title_to_file, + NULL); perror("err: failed to open editor"); return 1; }