Merge pull request 'handle EDITOR properly' (#1) from notchoc/ssm:master into master
Reviewed-on: https://codeberg.org/night0721/ssm/pulls/1
This commit is contained in:
commit
d30e0e24dc
1 changed files with 11 additions and 13 deletions
24
ssm.c
24
ssm.c
|
@ -31,7 +31,7 @@ get_database_path()
|
||||||
if (db[0] == '~') {
|
if (db[0] == '~') {
|
||||||
char *home = getenv("HOME");
|
char *home = getenv("HOME");
|
||||||
if (home == NULL) {
|
if (home == NULL) {
|
||||||
fprintf(stderr, "HOME not defined\n");
|
fprintf(stderr, "$HOME not defined\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
db_path = malloc((strlen(db) + strlen(home)) * sizeof(char));
|
db_path = malloc((strlen(db) + strlen(home)) * sizeof(char));
|
||||||
|
@ -257,21 +257,19 @@ main(int argc, char **argv)
|
||||||
/* todo: accept time */
|
/* todo: accept time */
|
||||||
add_event(time(NULL) + 60, name, description);
|
add_event(time(NULL) + 60, name, description);
|
||||||
} else if (strcmp(argv[1], "edit") == 0) {
|
} else if (strcmp(argv[1], "edit") == 0) {
|
||||||
char *editor = getenv("EDITOR");
|
const char *e = getenv("EDITOR");
|
||||||
if (editor == NULL) {
|
if (e == NULL) {
|
||||||
fprintf(stderr, "EDITOR not defined\n");
|
e = editor;
|
||||||
return EXIT_FAILURE;
|
fprintf(stderr, "$EDITOR not defined, falling back to %s\n", e);
|
||||||
}
|
}
|
||||||
char *db_path = get_database_path();
|
char *db_path = get_database_path();
|
||||||
char *cmd = malloc((strlen(editor) + strlen(db_path) + 1) * sizeof(char));
|
if (!db_path) {
|
||||||
if (cmd == NULL) {
|
fprintf(stderr, "Cannot find database path\n");
|
||||||
perror("malloc");
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
sprintf(cmd, "%s %s", editor, db_path);
|
execlp(e, e, db_path, NULL);
|
||||||
/* spawn $EDITOR */
|
perror("Failed to spawn editor");
|
||||||
system(cmd);
|
return EXIT_FAILURE;
|
||||||
free(cmd);
|
|
||||||
free(db_path);
|
|
||||||
} else if (strcmp(argv[1], "list") == 0) {
|
} else if (strcmp(argv[1], "list") == 0) {
|
||||||
/* accept argv[2] as timerange */
|
/* accept argv[2] as timerange */
|
||||||
list_events(events, &num_events);
|
list_events(events, &num_events);
|
||||||
|
|
Loading…
Reference in a new issue