mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Add '!' command to spawn a shell in cwd
This commit is contained in:
parent
7273c9d681
commit
d53e604cc2
44
noice.c
44
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);
|
||||
|
|
Loading…
Reference in a new issue