瀏覽代碼

Add '!' command to spawn a shell in cwd

master
sin 10 年之前
父節點
當前提交
d53e604cc2
共有 1 個文件被更改,包括 28 次插入16 次删除
  1. +28
    -16
      noice.c

+ 28
- 16
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…
取消
儲存