Add nosymlinkinfo option

This commit is contained in:
Nikita Ivanov 2022-06-28 20:56:52 +05:00
parent 61b6edb83b
commit 8e3dbc40d7
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
5 changed files with 24 additions and 10 deletions

View File

@ -282,6 +282,10 @@ for image previews.
.B noimages
Print only text and do not use any image previewing method.
.
.TP
.B nosymlinkinfo
Do not print resolved path of symbolic links.
.
.SS Defining custom previews
.
A snippet below defines a new preview with name

View File

@ -17,6 +17,11 @@
#define ACCEPT(x) CHECK_OK(accept(x))
#define NOT_ACCEPT(x) CHECK_NULL(accept(x))
#define DEF_OPTION(name, type, val) { (#name), (type), { .val = &ctpv.opts.name } }
#define DEF_OPTION_BOOL(name) DEF_OPTION(name, OPTION_BOOL, i)
#define DEF_OPTION_INT(name) DEF_OPTION(name, OPTION_INT, i)
#define DEF_OPTION_STR(name) DEF_OPTION(name, OPTION_STR, s)
struct Option {
char *name;
enum {
@ -41,9 +46,10 @@ static Token token;
static VectorPreview *previews;
static struct Option options[] = {
{ "forcekitty", OPTION_BOOL, { .i = &ctpv.opts.forcekitty } },
{ "forcechafa", OPTION_BOOL, { .i = &ctpv.opts.forcechafa } },
{ "noimages", OPTION_BOOL, { .i = &ctpv.opts.noimages } },
DEF_OPTION_BOOL(forcekitty),
DEF_OPTION_BOOL(forcechafa),
DEF_OPTION_BOOL(noimages),
DEF_OPTION_BOOL(nosymlinkinfo),
};
static void any_type_null(char **s)

View File

@ -210,10 +210,12 @@ static int preview(int argc, char *argv[])
GET_PARG(y, 4);
GET_PARG(id, 5);
ERRCHK_RET_OK(init_previews());
struct InputFile input_f;
ERRCHK_RET_OK(get_input_file(f, &input_f));
if (*input_f.link) {
if (!ctpv.opts.nosymlinkinfo && *input_f.link) {
printf("\033[1;36mSymlink points to:\033[m\n\t%s\n\n", input_f.link);
fflush(stdout);
@ -231,8 +233,6 @@ static int preview(int argc, char *argv[])
ERRCHK_RET_OK(init_magic());
ERRCHK_RET_OK(init_previews());
const char *mimetype;
ERRCHK_RET(!(mimetype = get_mimetype(input_f.path)));

View File

@ -14,7 +14,7 @@ struct CTPV {
} mode;
char *server_id_s;
struct {
int forcekitty, forcechafa, noimages;
int forcekitty, forcechafa, noimages, nosymlinkinfo;
} opts;
};

View File

@ -31,12 +31,16 @@ static char *prepend_helpers(char *str, size_t len)
return buf;
}
#define OPT_SETENV(name) \
ERRCHK_RET_ERN(setenv((#name), ctpv.opts.name ? "1" : "", 1) == -1)
int run_script(char *script, size_t script_len, int *exitcode, int *signal,
SpawnProg sp, void *sp_arg)
{
ERRCHK_RET_ERN(setenv("forcekitty", ctpv.opts.forcekitty ? "1" : "", 1) == -1);
ERRCHK_RET_ERN(setenv("forcechafa", ctpv.opts.forcechafa ? "1" : "", 1) == -1);
ERRCHK_RET_ERN(setenv("noimages", ctpv.opts.noimages ? "1" : "", 1) == -1);
OPT_SETENV(forcechafa);
OPT_SETENV(forcekitty);
OPT_SETENV(noimages);
OPT_SETENV(nosymlinkinfo);
char *scr = prepend_helpers(script, script_len);
char *args[] = SHELL_ARGS(scr);