From: Michael D. Lowis Date: Mon, 20 May 2019 17:11:56 +0000 (-0400) Subject: added logic to populate buffer from stdin X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=114539ab9e6a5ddd4ab32c8dc67b64e6c8770b81;p=projs%2Ftide.git added logic to populate buffer from stdin --- diff --git a/TODO.md b/TODO.md index e0df5b9..06bae82 100644 --- a/TODO.md +++ b/TODO.md @@ -4,8 +4,8 @@ ## STAGING -* tide: ability to populate scratch buffer from stdin * tfetch: read rules from rcfile in home and curr dir +* tfetch: ls results instead of pcmanfm on right click directory * tide: gap buffer does not handle UTF-8 currently ## BACKLOG diff --git a/inc/edit.h b/inc/edit.h index 9394b52..bb75120 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -180,6 +180,7 @@ bool job_poll(int ms); void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data); void job_start(char** cmd, char* data, size_t ndata, View* dest); int job_run(char** cmd); +void job_readfd(int fd, View* view); /* Common Shortcuts *****************************************************************************/ diff --git a/src/lib/job.c b/src/lib/job.c index 12ff105..5f4ed42 100644 --- a/src/lib/job.c +++ b/src/lib/job.c @@ -173,3 +173,9 @@ int job_run(char** cmd) { } while (!WIFEXITED(status) && !WIFSIGNALED(status)); return WEXITSTATUS(status); } + +void job_readfd(int fd, View* view) { + struct PipeData* pipedata = calloc(1, sizeof(struct PipeData)); + pipedata->dest = view; + job_spawn(fd, pipe_read, NULL, pipedata); +} diff --git a/src/tide.c b/src/tide.c index 473c89b..10399b0 100644 --- a/src/tide.c +++ b/src/tide.c @@ -294,6 +294,7 @@ void win_quit(void) { } else { if (fork()) exit(0); /* fork into background if we still have selection */ } + } before = X.now; } @@ -667,10 +668,14 @@ int main(int argc, char** argv) { if (*argv) { char* path = realpath(*argv, NULL); if (!path) path = strdup(*argv); /* if file doesnt exist, use the original name */ - view_init(win_view(EDIT), path); - win_setln(line_num); - win_title(path); - win_prop_set("FILE", "file", path); + if (!strcmp("-", path)) { + job_readfd(STDIN_FILENO, win_view(EDIT)); + } else { + view_init(win_view(EDIT), path); + win_setln(line_num); + win_title(path); + win_prop_set("FILE", "file", path); + } free(path); }