Simplified it_shell_cmd() using SXIV_IMG env-variable
This commit is contained in:
parent
de6b58a315
commit
9fa0bbca17
57
commands.c
57
commands.c
|
@ -16,7 +16,9 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _POSIX_C_SOURCE 200112L /* for setenv(3) */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
@ -345,45 +347,27 @@ int it_open_with(arg_t a) {
|
||||||
warn("could not exec: %s", prog);
|
warn("could not exec: %s", prog);
|
||||||
exit(1);
|
exit(1);
|
||||||
} else if (pid < 0) {
|
} else if (pid < 0) {
|
||||||
warn("could not for. program was: %s", prog);
|
warn("could not fork. program was: %s", prog);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int it_shell_cmd(arg_t a) {
|
int it_shell_cmd(arg_t a) {
|
||||||
const char *cline = (const char*) a;
|
int n, status;
|
||||||
char *cn, *cmdline;
|
const char *cmdline = (const char*) a;
|
||||||
const char *co, *fpath;
|
|
||||||
int fpcnt, fplen, status;
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if (!cline || !*cline)
|
if (!cmdline || !*cmdline)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* build command line: */
|
n = mode == MODE_IMAGE ? fileidx : tns.sel;
|
||||||
fpcnt = 0;
|
|
||||||
co = cline - 1;
|
if (setenv("SXIV_IMG", files[n].path, 1) < 0) {
|
||||||
while ((co = strchr(co + 1, '#')))
|
warn("could not change env.-variable: SXIV_IMG. command line was: %s",
|
||||||
fpcnt++;
|
cmdline);
|
||||||
if (!fpcnt)
|
|
||||||
return 0;
|
return 0;
|
||||||
fpath = files[mode == MODE_IMAGE ? fileidx : tns.sel].path;
|
|
||||||
fplen = strlen(fpath);
|
|
||||||
cn = cmdline = (char*) s_malloc((strlen(cline) + fpcnt * (fplen + 2)) *
|
|
||||||
sizeof(char));
|
|
||||||
/* replace all '#' with filename: */
|
|
||||||
for (co = cline; *co; co++) {
|
|
||||||
if (*co == '#') {
|
|
||||||
*cn++ = '"';
|
|
||||||
strcpy(cn, fpath);
|
|
||||||
cn += fplen;
|
|
||||||
*cn++ = '"';
|
|
||||||
} else {
|
|
||||||
*cn++ = *co;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*cn = '\0';
|
|
||||||
|
|
||||||
win_set_cursor(&win, CURSOR_WATCH);
|
win_set_cursor(&win, CURSOR_WATCH);
|
||||||
|
|
||||||
|
@ -402,17 +386,16 @@ int it_shell_cmd(arg_t a) {
|
||||||
WEXITSTATUS(status), cmdline);
|
WEXITSTATUS(status), cmdline);
|
||||||
|
|
||||||
if (mode == MODE_IMAGE) {
|
if (mode == MODE_IMAGE) {
|
||||||
if (fileidx < tns.cnt)
|
|
||||||
tns_load(&tns, fileidx, &files[fileidx], False, True);
|
|
||||||
img_close(&img, 1);
|
img_close(&img, 1);
|
||||||
load_image(fileidx);
|
load_image(fileidx);
|
||||||
} else {
|
}
|
||||||
if (!tns_load(&tns, tns.sel, &files[tns.sel], True, False)) {
|
if (!tns_load(&tns, n, &files[n], True, mode == MODE_IMAGE) &&
|
||||||
remove_file(tns.sel, 0);
|
mode == MODE_THUMB)
|
||||||
tns.dirty = 1;
|
{
|
||||||
if (tns.sel >= tns.cnt)
|
remove_file(tns.sel, 0);
|
||||||
tns.sel = tns.cnt - 1;
|
tns.dirty = 1;
|
||||||
}
|
if (tns.sel >= tns.cnt)
|
||||||
|
tns.sel = tns.cnt - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
@ -420,7 +403,5 @@ end:
|
||||||
win_set_cursor(&win, CURSOR_ARROW);
|
win_set_cursor(&win, CURSOR_ARROW);
|
||||||
/* else: cursor gets reset in redraw() */
|
/* else: cursor gets reset in redraw() */
|
||||||
|
|
||||||
free(cmdline);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
14
config.h
14
config.h
|
@ -110,11 +110,15 @@ static const keymap_t keys[] = {
|
||||||
/* open current image with given program: */
|
/* open current image with given program: */
|
||||||
{ True, XK_g, it_open_with, (arg_t) "gimp" },
|
{ True, XK_g, it_open_with, (arg_t) "gimp" },
|
||||||
|
|
||||||
/* run shell command line on current file ('#' is replaced by file path: */
|
/* run shell command line on current file ("$SXIV_IMG"): */
|
||||||
{ True, XK_less, it_shell_cmd, (arg_t) "mogrify -rotate -90 #" },
|
{ True, XK_less, it_shell_cmd, (arg_t) \
|
||||||
{ True, XK_greater, it_shell_cmd, (arg_t) "mogrify -rotate +90 #" },
|
"mogrify -rotate -90 \"$SXIV_IMG\"" },
|
||||||
{ True, XK_comma, it_shell_cmd, (arg_t) "jpegtran -rotate 270 -copy all -outfile # #" },
|
{ True, XK_greater, it_shell_cmd, (arg_t) \
|
||||||
{ True, XK_period, it_shell_cmd, (arg_t) "jpegtran -rotate 90 -copy all -outfile # #" },
|
"mogrify -rotate +90 \"$SXIV_IMG\"" },
|
||||||
|
{ True, XK_comma, it_shell_cmd, (arg_t) \
|
||||||
|
"jpegtran -rotate 270 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" },
|
||||||
|
{ True, XK_period, it_shell_cmd, (arg_t) \
|
||||||
|
"jpegtran -rotate 90 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" },
|
||||||
};
|
};
|
||||||
|
|
||||||
/* mouse button mappings for image mode: */
|
/* mouse button mappings for image mode: */
|
||||||
|
|
Loading…
Reference in New Issue