mirror of
https://github.com/NikitaIvanovV/ctpv.git
synced 2024-11-27 23:13:07 +01:00
Add support for gpg-encrypted files
This commit is contained in:
parent
06ae795b4e
commit
eb43b4e836
@ -54,6 +54,7 @@ For example, you only need either `elinks`, `lynx` or
|
|||||||
| archive | `atool` |
|
| archive | `atool` |
|
||||||
| diff | `colordiff` `delta` `diff-so-fancy` |
|
| diff | `colordiff` `delta` `diff-so-fancy` |
|
||||||
| directory | `ls` |
|
| directory | `ls` |
|
||||||
|
| gpg-encrypted | `gpg` |
|
||||||
| html | `elinks` `lynx` `w3m` |
|
| html | `elinks` `lynx` `w3m` |
|
||||||
| image | `ueberzug` `chafa` |
|
| image | `ueberzug` `chafa` |
|
||||||
| json | `jq` |
|
| json | `jq` |
|
||||||
|
@ -24,7 +24,7 @@ function process_file(file, i, line, arr, t, p, p_len) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match(line, /^#\s*(\w+):\s*(.*)/, arr) == 0)
|
if (match(line, /^#\s*([a-zA-Z0-9_-]+):\s*(.*)/, arr) == 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
t = arr[1]
|
t = arr[1]
|
||||||
|
10
doc/ctpv.1
10
doc/ctpv.1
@ -113,6 +113,9 @@ T}
|
|||||||
directory T{
|
directory T{
|
||||||
ls
|
ls
|
||||||
T}
|
T}
|
||||||
|
gpg-encrypted T{
|
||||||
|
gpg
|
||||||
|
T}
|
||||||
html T{
|
html T{
|
||||||
elinks lynx w3m
|
elinks lynx w3m
|
||||||
T}
|
T}
|
||||||
@ -316,6 +319,13 @@ Print only text and do not use any image previewing method.
|
|||||||
.B nosymlinkinfo
|
.B nosymlinkinfo
|
||||||
Do not print resolved path of symbolic links.
|
Do not print resolved path of symbolic links.
|
||||||
.
|
.
|
||||||
|
.TP
|
||||||
|
.B showgpg
|
||||||
|
Preview
|
||||||
|
.BR gpg (1)
|
||||||
|
encrypted files.
|
||||||
|
Filename must have \(lq.gpg\(rq extension.
|
||||||
|
.
|
||||||
.SS Defining custom previews
|
.SS Defining custom previews
|
||||||
.
|
.
|
||||||
A snippet below defines a new preview with name
|
A snippet below defines a new preview with name
|
||||||
|
143
previews.h
143
previews.h
@ -10,88 +10,89 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define PNAME(n) prev_scr_##n##_sh
|
#define PNAME(n) prev_scr_##n##_sh
|
||||||
#define PR(e, t, s, n) { #n, e, t, s, PNAME(n), 0, 0, LEN(PNAME(n)) }
|
#define PR(e, t, s, n, a) { #n, e, t, s, PNAME(n), 0, 0, a, LEN(PNAME(n)) }
|
||||||
|
|
||||||
Preview b_previews[] = {
|
Preview b_previews[] = {
|
||||||
PR(NULL, NULL, NULL, any),
|
PR(NULL, NULL, NULL, any, PREV_ATTR_NONE),
|
||||||
|
|
||||||
PR("md", NULL, NULL, mdcat),
|
PR("md", NULL, NULL, mdcat, PREV_ATTR_NONE),
|
||||||
PR("torrent", NULL, NULL, torrent),
|
PR("torrent", NULL, NULL, torrent, PREV_ATTR_NONE),
|
||||||
PR("odt", NULL, NULL, odt),
|
PR("odt", NULL, NULL, odt, PREV_ATTR_NONE),
|
||||||
|
|
||||||
PR(NULL, "text", NULL, bat),
|
PR(NULL, "text", NULL, bat, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", NULL, highlight),
|
PR(NULL, "text", NULL, highlight, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", NULL, source_highlight),
|
PR(NULL, "text", NULL, source_highlight, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", NULL, cat),
|
PR(NULL, "text", NULL, cat, PREV_ATTR_NONE),
|
||||||
|
|
||||||
PR(NULL, "image", NULL, image),
|
PR(NULL, "image", NULL, image, PREV_ATTR_NONE),
|
||||||
PR(NULL, "video", NULL, video),
|
PR(NULL, "video", NULL, video, PREV_ATTR_NONE),
|
||||||
|
|
||||||
PR(NULL, "application", "pdf", pdf),
|
PR(NULL, "application", "pdf", pdf, PREV_ATTR_NONE),
|
||||||
PR(NULL, "application", "json", jq),
|
PR(NULL, "application", "json", jq, PREV_ATTR_NONE),
|
||||||
|
|
||||||
PR(NULL, "inode", "directory", ls),
|
PR(NULL, "inode", "directory", ls, PREV_ATTR_NONE),
|
||||||
PR(NULL, "inode", "symlink", symlink),
|
PR(NULL, "inode", "symlink", symlink, PREV_ATTR_NONE),
|
||||||
|
|
||||||
PR(NULL, "text", "html", elinks),
|
PR(NULL, "text", "html", elinks, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", "html", lynx),
|
PR(NULL, "text", "html", lynx, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", "html", w3m),
|
PR(NULL, "text", "html", w3m, PREV_ATTR_NONE),
|
||||||
|
|
||||||
PR(NULL, "text", "x-diff", delta),
|
PR(NULL, "text", "x-diff", delta, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", "x-patch", delta),
|
PR(NULL, "text", "x-patch", delta, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", "x-diff", diff_so_fancy),
|
PR(NULL, "text", "x-diff", diff_so_fancy, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", "x-patch", diff_so_fancy),
|
PR(NULL, "text", "x-patch", diff_so_fancy, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", "x-diff", colordiff),
|
PR(NULL, "text", "x-diff", colordiff, PREV_ATTR_NONE),
|
||||||
PR(NULL, "text", "x-patch", colordiff),
|
PR(NULL, "text", "x-patch", colordiff, PREV_ATTR_NONE),
|
||||||
|
|
||||||
PR("tar.gz", NULL, NULL, atool),
|
PR("tar.gz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tgz", NULL, NULL, atool),
|
PR("tgz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tgz", NULL, NULL, atool),
|
PR("tgz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tar.gz", NULL, NULL, atool),
|
PR("tar.gz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tgz", NULL, NULL, atool),
|
PR("tgz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tar.bz", NULL, NULL, atool),
|
PR("tar.bz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tbz", NULL, NULL, atool),
|
PR("tbz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tar.bz2", NULL, NULL, atool),
|
PR("tar.bz2", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tbz2", NULL, NULL, atool),
|
PR("tbz2", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tar.Z", NULL, NULL, atool),
|
PR("tar.Z", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tZ", NULL, NULL, atool),
|
PR("tZ", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tar.lzo", NULL, NULL, atool),
|
PR("tar.lzo", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tzo", NULL, NULL, atool),
|
PR("tzo", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tar.lz", NULL, NULL, atool),
|
PR("tar.lz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tlz", NULL, NULL, atool),
|
PR("tlz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tar.xz", NULL, NULL, atool),
|
PR("tar.xz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("txz", NULL, NULL, atool),
|
PR("txz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tar.7z", NULL, NULL, atool),
|
PR("tar.7z", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("t7z", NULL, NULL, atool),
|
PR("t7z", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("tar", NULL, NULL, atool),
|
PR("tar", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("zip", NULL, NULL, atool),
|
PR("zip", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("jar", NULL, NULL, atool),
|
PR("jar", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("war", NULL, NULL, atool),
|
PR("war", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("rar", NULL, NULL, atool),
|
PR("rar", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("lha", NULL, NULL, atool),
|
PR("lha", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("lzh", NULL, NULL, atool),
|
PR("lzh", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("7z", NULL, NULL, atool),
|
PR("7z", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("alz", NULL, NULL, atool),
|
PR("alz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("ace", NULL, NULL, atool),
|
PR("ace", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("a", NULL, NULL, atool),
|
PR("a", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("arj", NULL, NULL, atool),
|
PR("arj", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("arc", NULL, NULL, atool),
|
PR("arc", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("rpm", NULL, NULL, atool),
|
PR("rpm", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("deb", NULL, NULL, atool),
|
PR("deb", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("cab", NULL, NULL, atool),
|
PR("cab", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("gz", NULL, NULL, atool),
|
PR("gz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("bz", NULL, NULL, atool),
|
PR("bz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("bz2", NULL, NULL, atool),
|
PR("bz2", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("Z", NULL, NULL, atool),
|
PR("Z", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("lzma", NULL, NULL, atool),
|
PR("lzma", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("lzo", NULL, NULL, atool),
|
PR("lzo", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("lz", NULL, NULL, atool),
|
PR("lz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("xz", NULL, NULL, atool),
|
PR("xz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("rz", NULL, NULL, atool),
|
PR("rz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("lrz", NULL, NULL, atool),
|
PR("lrz", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("7z", NULL, NULL, atool),
|
PR("7z", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
PR("cpio", NULL, NULL, atool),
|
PR("cpio", NULL, NULL, atool, PREV_ATTR_NONE),
|
||||||
|
|
||||||
|
PR("gpg", NULL, NULL, gpg, PREV_ATTR_EXT_SHORT),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* vim: set nowrap: */
|
/* vim: set nowrap: */
|
||||||
|
6
sh/prev/gpg.sh
Normal file
6
sh/prev/gpg.sh
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# gpg-encrypted: gpg
|
||||||
|
|
||||||
|
# "showgpg" option must be enabled for this preview to work
|
||||||
|
[ -z "$showgpg" ] && exit 127
|
||||||
|
|
||||||
|
gpg -d -- "$f" 2>&1
|
@ -51,6 +51,7 @@ static struct Option options[] = {
|
|||||||
DEF_OPTION_BOOL(forcechafa),
|
DEF_OPTION_BOOL(forcechafa),
|
||||||
DEF_OPTION_BOOL(noimages),
|
DEF_OPTION_BOOL(noimages),
|
||||||
DEF_OPTION_BOOL(nosymlinkinfo),
|
DEF_OPTION_BOOL(nosymlinkinfo),
|
||||||
|
DEF_OPTION_BOOL(showgpg),
|
||||||
};
|
};
|
||||||
|
|
||||||
static void any_type_null(char **s)
|
static void any_type_null(char **s)
|
||||||
@ -78,6 +79,7 @@ static void add_preview(char *name, char *script, char *type, char *subtype,
|
|||||||
.type = type,
|
.type = type,
|
||||||
.subtype = subtype,
|
.subtype = subtype,
|
||||||
.ext = ext,
|
.ext = ext,
|
||||||
|
.attrs = PREV_ATTR_NONE,
|
||||||
.order = 1 /* custom previews are always prioritized */
|
.order = 1 /* custom previews are always prioritized */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ struct CTPV {
|
|||||||
char *server_id_s;
|
char *server_id_s;
|
||||||
struct {
|
struct {
|
||||||
int forcekitty, forcekittyanim, forcechafa, noimages, nosymlinkinfo;
|
int forcekitty, forcekittyanim, forcechafa, noimages, nosymlinkinfo;
|
||||||
|
int showgpg;
|
||||||
} opts;
|
} opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,11 +89,19 @@ static void break_mimetype(char *mimetype, char **type, char **subtype)
|
|||||||
static Preview *find_preview(const char *type, const char *subtype, const char *ext, size_t *i)
|
static Preview *find_preview(const char *type, const char *subtype, const char *ext, size_t *i)
|
||||||
{
|
{
|
||||||
Preview *p;
|
Preview *p;
|
||||||
|
const char *rext;
|
||||||
|
|
||||||
for (; *i < previews.len; (*i)++) {
|
for (; *i < previews.len; (*i)++) {
|
||||||
p = previews.list[*i];
|
p = previews.list[*i];
|
||||||
|
|
||||||
if (p->ext && strcmpnull(p->ext, ext) != 0)
|
if (p->attrs & PREV_ATTR_EXT_SHORT) {
|
||||||
|
if ((rext = strrchr(ext, '.')))
|
||||||
|
rext += 1;
|
||||||
|
} else {
|
||||||
|
rext = ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->ext && strcmpnull(p->ext, rext) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (p->type && strcmpnull(p->type, type) != 0)
|
if (p->type && strcmpnull(p->type, type) != 0)
|
||||||
|
@ -7,9 +7,15 @@
|
|||||||
|
|
||||||
#define MIMETYPE_MAX 64
|
#define MIMETYPE_MAX 64
|
||||||
|
|
||||||
|
enum PreviewAttr {
|
||||||
|
PREV_ATTR_NONE = 0,
|
||||||
|
PREV_ATTR_EXT_SHORT = 1 << 0,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name, *ext, *type, *subtype, *script;
|
char *name, *ext, *type, *subtype, *script;
|
||||||
int order, priority;
|
int order, priority;
|
||||||
|
enum PreviewAttr attrs;
|
||||||
size_t script_len;
|
size_t script_len;
|
||||||
} Preview;
|
} Preview;
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ int run_script(char *script, size_t script_len, int *exitcode, int *signal,
|
|||||||
OPT_SETENV(forcechafa);
|
OPT_SETENV(forcechafa);
|
||||||
OPT_SETENV(noimages);
|
OPT_SETENV(noimages);
|
||||||
OPT_SETENV(nosymlinkinfo);
|
OPT_SETENV(nosymlinkinfo);
|
||||||
|
OPT_SETENV(showgpg);
|
||||||
|
|
||||||
char *scr = prepend_helpers(script, script_len);
|
char *scr = prepend_helpers(script, script_len);
|
||||||
char *args[] = SHELL_ARGS(scr);
|
char *args[] = SHELL_ARGS(scr);
|
||||||
|
Loading…
Reference in New Issue
Block a user