From 8e54820c10a7e90316fc5e1abf52fbde9c4fd52d Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 28 Nov 2024 13:49:51 +0100 Subject: [PATCH] findmnt: add --hyperlink command line option Signed-off-by: Karel Zak --- bash-completion/findmnt | 1 + misc-utils/findmnt.8.adoc | 3 +++ misc-utils/findmnt.c | 23 +++++++++++++++++++---- misc-utils/findmnt.h | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/bash-completion/findmnt b/bash-completion/findmnt index 859439472b..2eb23446f7 100644 --- a/bash-completion/findmnt +++ b/bash-completion/findmnt @@ -111,6 +111,7 @@ _findmnt_module() --evaluate --tab-file --first-only + --hyperlink --invert --json --list diff --git a/misc-utils/findmnt.8.adoc b/misc-utils/findmnt.8.adoc index f29f965421..23fb14da56 100644 --- a/misc-utils/findmnt.8.adoc +++ b/misc-utils/findmnt.8.adoc @@ -57,6 +57,9 @@ The search direction, either *forward* or *backward*. *-e*, *--evaluate*:: Convert all tags (LABEL, UUID, PARTUUID, or PARTLABEL) to the corresponding device names for the SOURCE column. It's an unusual situation, but the same tag may be duplicated (used for more devices). For this purpose, there is SOURCES (pl.) column. This column displays by multi-line cell all devices where the tag is detected by libblkid. This option makes sense for _fstab_ only. +*--hyperlink*[=_mode_]:: +Print mountpoint paths as terminal hyperlinks. The _mode_ can be set to "always", "never", or "auto". The optional argument _when_ can be set to "auto", "never", or "always". If the _when_ argument is omitted, it will default to "auto". The "auto" setting means that hyperlinks will only be used if the output is on a terminal. + *-F*, *--tab-file* _path_:: Search in an alternative file. If used with *--fstab*, *--mtab* or *--kernel*, then it overrides the default paths. If specified more than once, then tree-like output is disabled (see the *--list* option). diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index 236e8e7a80..736c20e038 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -50,6 +50,7 @@ #include "mangle.h" #include "buffer.h" #include "column-list-table.h" +#include "ttyutils.h" #include "findmnt.h" @@ -1555,9 +1556,12 @@ static void __attribute__((__noreturn__)) list_colunms(struct findmnt *findmnt) exit(EXIT_SUCCESS); } -static struct libscols_table *init_scols_table(unsigned int flags, bool use_filter) +static struct libscols_table *init_scols_table(struct findmnt *findmnt) { struct libscols_table *table = scols_new_table(); + unsigned int flags = findmnt->flags; + bool use_filter = findmnt->filter? true: false; + if (!table) { warn(_("failed to allocate output table")); goto leave; @@ -1592,6 +1596,10 @@ static struct libscols_table *init_scols_table(unsigned int flags, bool use_filt warn(_("failed to allocate output column")); goto leave; } + + if (findmnt->uri && id == COL_TARGET) + scols_column_set_uri(cl, findmnt->uri); + /* multi-line cells (now used for SOURCES) */ if (fl & SCOLS_FL_WRAP) scols_column_set_wrapfunc(cl, @@ -1688,7 +1696,8 @@ int main(int argc, char *argv[]) FINDMNT_OPT_PSEUDO, FINDMNT_OPT_REAL, FINDMNT_OPT_VFS_ALL, - FINDMNT_OPT_SHADOWED + FINDMNT_OPT_SHADOWED, + FINDMNT_OPT_HYPERLINK }; static const struct option longopts[] = { @@ -1737,6 +1746,7 @@ int main(int argc, char *argv[]) { "pseudo", no_argument, NULL, FINDMNT_OPT_PSEUDO }, { "vfs-all", no_argument, NULL, FINDMNT_OPT_VFS_ALL }, { "shadowed", no_argument, NULL, FINDMNT_OPT_SHADOWED }, + { "hyperlink", optional_argument, NULL, FINDMNT_OPT_HYPERLINK }, { "list-columns", no_argument, NULL, 'H' }, { NULL, 0, NULL, 0 } }; @@ -1930,7 +1940,11 @@ int main(int argc, char *argv[]) case FINDMNT_OPT_SHADOWED: findmnt.flags |= FL_SHADOWED; break; - + case FINDMNT_OPT_HYPERLINK: + if (hyperlinkwanted_or_err(optarg, + _("invalid hyperlink argument"))) + findmnt.uri = xgethosturi(NULL); + break; case 'H': collist = 1; break; @@ -2061,12 +2075,13 @@ int main(int argc, char *argv[]) * initialize libsmartcols */ scols_init_debug(0); - table = init_scols_table(findmnt.flags, findmnt.filter? true: false); + table = init_scols_table(&findmnt); if (!table) goto leave; init_scols_filter(table, findmnt.filter, findmnt.flags); + /* * Fill in data to the output table */ diff --git a/misc-utils/findmnt.h b/misc-utils/findmnt.h index a8ebdea1c1..5c74bddc4b 100644 --- a/misc-utils/findmnt.h +++ b/misc-utils/findmnt.h @@ -39,6 +39,7 @@ struct findmnt { struct libmnt_cache *cache; unsigned int flags; int parse_nerrors; + char *uri; struct libscols_filter *filter; }; -- 2.47.3