/* Command Executions
*****************************************************************************/
bool exec_reap(void);
-void exec_job(char** cmd, char* data, size_t ndata, View* dest);
+void exec_job(char** cmd, char* data, size_t ndata, View* dest, void (*donefn)(int));
int exec_cmd(char** cmd, char* text, char** out, char** err);
int exec_spawn(char** cmd, int* in, int* out);
} Rcvr;
struct Job {
- Job* next; /* Pointer to previous job in the job list */
- Job* prev; /* Pointer to next job in the job list */
- Proc proc; /* Process id and descriptors */
- size_t ndata; /* number of bytes to write to stdout */
- size_t nwrite; /* number of bytes written to stdout so far */
- char* data; /* data to write to stdout */
- Rcvr err_rcvr; /* reciever for the error output of the job */
- Rcvr out_rcvr; /* receiver for the normal output of the job */
- View* dest; /* destination view where output will be placed */
+ Job* next; /* Pointer to previous job in the job list */
+ Job* prev; /* Pointer to next job in the job list */
+ Proc proc; /* Process id and descriptors */
+ size_t ndata; /* number of bytes to write to stdout */
+ size_t nwrite; /* number of bytes written to stdout so far */
+ char* data; /* data to write to stdout */
+ Rcvr err_rcvr; /* reciever for the error output of the job */
+ Rcvr out_rcvr; /* receiver for the normal output of the job */
+ View* dest; /* destination view where output will be placed */
+ void (*donefn)(int); /* function called with return status of the job */
};
static Job* JobList = NULL;
static int execute(char** cmd, Proc* proc);
bool exec_reap(void) {
+ int status;
Job* job = JobList;
while (job) {
if (job_done(job)) {
rcvr_finish(&(job->out_rcvr));
rcvr_finish(&(job->err_rcvr));
+ waitpid(job->proc.pid, &status, WNOHANG);
+ if (job->donefn) job->donefn(status);
job = job_finish(job);
} else {
job = job->next;
}
}
- while (waitpid(-1, NULL, WNOHANG) > 0);
+ if (JobList == NULL)
+ while (waitpid(-1, &status, WNOHANG) > 0);
return (JobList != NULL);
}
-void exec_job(char** cmd, char* data, size_t ndata, View* dest) {
+void exec_job(char** cmd, char* data, size_t ndata, View* dest, void (*donefn)(int)) {
Job* job = calloc(1, sizeof(Job));
job->proc.pid = execute(cmd, &(job->proc));
if (job->proc.pid < 0) {
job->nwrite = 0;
job->data = data;
job->next = JobList;
+ job->donefn = donefn;
if (JobList) JobList->prev = job;
JobList = job;
/* register watch events for file descriptors */
if (Selections[CLIPBOARD].text) {
char* text = Selections[CLIPBOARD].text;
size_t len = strlen(text);
- exec_job((char*[]){ "xcpd", NULL }, text, len, NULL);
+ exec_job((char*[]){ "xcpd", NULL }, text, len, NULL, NULL);
while (event_poll(100));
}
}
fi
export PICKTITLE="Pick File ($PWD)"
-find $1 -not -path '*/\.*' -type f | sed "s|^\./||" | pick | xargs -r tide
+file="$(find $1 -not -path '*/\.*' -type f | sed 's|^\./||' | pick)"
+tide "$file"
if [ "" == "$TAGFILE" ] || [ "" == "$ACTION" ]; then
usage
fi
-
+ma
printtags(){
cat "$TAGFILE" | grep -v '^!' | cut -f1 | uniq
}
TAG=$(printtags | pick)
[ "" == "$TAG" ] && exit
fi
- awk -v TAG="$TAG" '
- BEGIN { FS = "[\t]+" }
- ($1 == TAG) {
- matchstr = $3
- sub(/^\//, "\"", matchstr)
- sub(/\$?\/;"$/, "\"", matchstr)
- gsub(/\*/, "\\*", matchstr)
- print "grep -Hn", matchstr, $2, "| cut -d: -f1,2"
- }
- ' "$TAGFILE" | /bin/sh | pick | xargs -r tide
+ file=$(awk -v TAG="$TAG" '
+ BEGIN { FS = "[\t]+" }
+ ($1 == TAG) {
+ matchstr = $3
+ sub(/^\//, "\"", matchstr)
+ sub(/\$?\/;"$/, "\"", matchstr)
+ gsub(/\*/, "\\*", matchstr)
+ gsub(/(\[|\])/, "\\\1", matchstr)
+ print "grep -Hn", matchstr, $2, "| cut -d: -f1,2"
+ }
+ ' "$TAGFILE" | /bin/sh | pick)
+ [ "" != "$file" ] && tide "$file"
}
export PICKTITLE="Pick CTag ($PWD)"
/* execute the job */
if (op == '!')
- free(input), exec_job(execcmd, NULL, 0, NULL);
+ free(input), exec_job(execcmd, NULL, 0, NULL, NULL);
else if (op == '>')
- exec_job(execcmd, input, len, tags);
+ exec_job(execcmd, input, len, tags, NULL);
else if (op == '|' || op == ':')
- exec_job(execcmd, input, len, edit);
+ exec_job(execcmd, input, len, edit, NULL);
else
- exec_job(execcmd, input, len, (op != '<' ? curr : edit));
+ exec_job(execcmd, input, len, (op != '<' ? curr : edit), NULL);
}
static void cmd_execwitharg(char* cmd, char* arg) {
free(cmd);
}
-
static void exec(char* cmd) {
/* skip leading space */
for (; *cmd && isspace(*cmd); cmd++);