diff options
author | Bert Münnich <ber.t@posteo.de> | 2014-01-02 23:19:31 +0100 |
---|---|---|
committer | Bert Münnich <ber.t@posteo.de> | 2014-01-02 23:19:31 +0100 |
commit | f2e0c492bd784a3a927550187e21cfbc6bbb0939 (patch) | |
tree | b5cf82fa59a82598adc4c4ab50b731f50f71a7bf /commands.c | |
parent | b2eae528ed54c3ee1509e410686fabc1c7ecc0b4 (diff) |
Moved external shell commands into exec/key-handler script
Gets called on all unset key mappings. Arguments are: key combo and
current file. Thanks to Francesco Orsenigo (xarvh) for the idea.
Diffstat (limited to 'commands.c')
-rw-r--r-- | commands.c | 66 |
1 files changed, 0 insertions, 66 deletions
@@ -504,69 +504,3 @@ bool it_toggle_alpha(arg_t a) return true; } -bool it_open_with(arg_t a) -{ - const char *prog = (const char*) a; - pid_t pid; - - if (prog == NULL || *prog == '\0') - return false; - - if ((pid = fork()) == 0) { - execlp(prog, prog, - files[mode == MODE_IMAGE ? fileidx : tns.sel].path, NULL); - warn("could not exec: %s", prog); - exit(EXIT_FAILURE); - } else if (pid < 0) { - warn("could not fork. program was: %s", prog); - } - return false; -} - -bool it_shell_cmd(arg_t a) -{ - int n, status; - const char *cmdline = (const char*) a; - pid_t pid; - - if (cmdline == NULL || *cmdline == '\0') - return false; - - n = mode == MODE_IMAGE ? fileidx : tns.sel; - - if (setenv("SXIV_IMG", files[n].path, 1) < 0) { - warn("could not set env.-variable: SXIV_IMG. command line was: %s", - cmdline); - return false; - } - - if ((pid = fork()) == 0) { - execl("/bin/sh", "/bin/sh", "-c", cmdline, NULL); - warn("could not exec: /bin/sh. command line was: %s", cmdline); - exit(EXIT_FAILURE); - } else if (pid < 0) { - warn("could not fork. command line was: %s", cmdline); - return false; - } - - win_set_cursor(&win, CURSOR_WATCH); - - waitpid(pid, &status, 0); - if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0) - warn("child exited with non-zero return value: %d. command line was: %s", - WEXITSTATUS(status), cmdline); - - if (mode == MODE_IMAGE) { - img_close(&img, true); - load_image(fileidx); - } - if (!tns_load(&tns, n, &files[n], true, mode == MODE_IMAGE) && - mode == MODE_THUMB) - { - remove_file(tns.sel, false); - tns.dirty = true; - if (tns.sel >= tns.cnt) - tns.sel = tns.cnt - 1; - } - return true; -} |