noice

small file browser
git clone git://git.2f30.org/noice
Log | Files | Refs | README | LICENSE

commit d53e604cc24f5b17985cf3bc5937d16c4a4ed2fc
parent 7273c9d6819c50ab546885f7d6d0e81d03b7ca16
Author: sin <sin@2f30.org>
Date:   Tue, 21 Oct 2014 14:21:00 +0100

Add '!' command to spawn a shell in cwd

Diffstat:
Mnoice.c | 44++++++++++++++++++++++++++++----------------
1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/noice.c b/noice.c @@ -76,6 +76,24 @@ void printmsg(char *msg); void printwarn(void); void printerr(int ret, char *prefix); +void +spawn(const char *file, const char *arg) +{ + pid_t pid; + int status; + + pid = fork(); + if (pid == 0) { + execlp(file, file, arg, NULL); + _exit(1); + } else { + /* Ignore interruptions */ + while (waitpid(pid, &status, 0) == -1) + DPRINTF_D(status); + DPRINTF_D(pid); + } +} + char * openwith(char *file) { @@ -234,6 +252,11 @@ nextsel(int *cur, int max) if (*cur > 0) (*cur) -= MIN((LINES - 4) / 2, *cur); break; + case '!': + exitcurses(); + spawn("/bin/sh", NULL); + initcurses(); + break; } return 0; @@ -405,13 +428,11 @@ begin: char *pathnew; char *name; char *bin; - pid_t pid; int fd; char *dir; char *tmp; regex_t re; struct history *hist; - int status; redraw: nlines = MIN(LINES - 4, n); @@ -451,7 +472,11 @@ redraw: } nochange: + if (chdir(path) == -1) + printwarn(); ret = nextsel(&cur, n); + if (chdir(ipath) == -1) + printwarn(); switch (ret) { case SEL_QUIT: free(path); @@ -542,20 +567,7 @@ nochange: } exitcurses(); - - /* Run program */ - pid = fork(); - if (pid == 0) { - execlp(bin, bin, pathnew, NULL); - _exit(0); - } else { - /* Ignore interruptions */ - while (waitpid(pid, &status, - 0) == -1) - DPRINTF_D(status); - DPRINTF_D(pid); - } - + spawn(bin, pathnew); initcurses(); free(pathnew);