commit 715197795c2917012fe205104133ce59535a62d3
parent 5d1474d7f1ad30adbfde82ce276d7468c102798b
Author: Remy Noulin <loader2x@gmail.com>
Date: Mon, 11 Feb 2019 14:21:30 -0500
support stdin in vop.c
debian/1-system.sh | 2 +-
dotfiles/vop.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 43 insertions(+), 5 deletions(-)
Diffstat:
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/debian/1-system.sh b/debian/1-system.sh
@@ -84,7 +84,7 @@ mkdir /etc/.git/hooks
etckeeper init
# install pick
-apt-get install autotools-dev automake
+apt-get install -y autotools-dev automake
git clone https://github.com/mptre/pick
cd pick
./autogen.sh
diff --git a/dotfiles/vop.c b/dotfiles/vop.c
@@ -1,14 +1,52 @@
#! /usr/bin/env sheepy
#include "libsheepyObject.h"
+#include <unistd.h>
+
+void open(char *s) {
+ var sp = splitG(s, ':');
+ if (lenG(sp) > 1) {
+ systemf("vim %s +%s", sp[0], sp[1]);
+ }
+ freeG(sp);
+}
int main(int ARGC, char** ARGV) {
if (ARGC > 1) {
- var sp = splitG(ARGV[1], ':');
- if (lenG(sp) > 1) {
- systemf("vim %s +%s", sp[0], sp[1]);
+ open(ARGV[1]);
+ }
+ else {
+ // no arguments
+ // check stdin
+
+ // input string
+ char *s = NULL;
+
+ // read all the data from stdin to s
+ fd_set readfds;
+ FD_ZERO(&readfds);
+ FD_SET(STDIN_FILENO, &readfds);
+
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 0;
+
+ int chr;
+
+ int sel_rv = select(1, &readfds, NULL, NULL, &timeout);
+ if (sel_rv > 0) {
+ while ((chr = getchar()) != EOF) appendG(&s,chr);
+ } else if (sel_rv == -1) {
+ perror("select failed");
}
- freeG(sp);
+
+ //logVarG(s);
+ if (isEmptyG(s)) {
+ XSUCCESS;
+ }
+
+ open(s);
+ free(s);
}
}