Browse Source

Add '!' command to spawn a shell in cwd

master
sin 10 years ago
parent
commit
d53e604cc2
1 changed files with 28 additions and 16 deletions
  1. +28
    -16
      noice.c

+ 28
- 16
noice.c View File

@@ -76,6 +76,24 @@ void printmsg(char *msg);
void printwarn(void); void printwarn(void);
void printerr(int ret, char *prefix); 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 * char *
openwith(char *file) openwith(char *file)
{ {
@@ -234,6 +252,11 @@ nextsel(int *cur, int max)
if (*cur > 0) if (*cur > 0)
(*cur) -= MIN((LINES - 4) / 2, *cur); (*cur) -= MIN((LINES - 4) / 2, *cur);
break; break;
case '!':
exitcurses();
spawn("/bin/sh", NULL);
initcurses();
break;
} }


return 0; return 0;
@@ -405,13 +428,11 @@ begin:
char *pathnew; char *pathnew;
char *name; char *name;
char *bin; char *bin;
pid_t pid;
int fd; int fd;
char *dir; char *dir;
char *tmp; char *tmp;
regex_t re; regex_t re;
struct history *hist; struct history *hist;
int status;


redraw: redraw:
nlines = MIN(LINES - 4, n); nlines = MIN(LINES - 4, n);
@@ -451,7 +472,11 @@ redraw:
} }


nochange: nochange:
if (chdir(path) == -1)
printwarn();
ret = nextsel(&cur, n); ret = nextsel(&cur, n);
if (chdir(ipath) == -1)
printwarn();
switch (ret) { switch (ret) {
case SEL_QUIT: case SEL_QUIT:
free(path); free(path);
@@ -542,20 +567,7 @@ nochange:
} }


exitcurses(); 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(); initcurses();


free(pathnew); free(pathnew);


Loading…
Cancel
Save