]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
findmnt: add --hyperlink command line option
authorKarel Zak <kzak@redhat.com>
Thu, 28 Nov 2024 12:49:51 +0000 (13:49 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 9 Dec 2024 09:24:34 +0000 (10:24 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
bash-completion/findmnt
misc-utils/findmnt.8.adoc
misc-utils/findmnt.c
misc-utils/findmnt.h

index 859439472ba47335c0dae84b987ddda86a869e8d..2eb23446f7ec3572eb74833f6b86721c59f287f7 100644 (file)
@@ -111,6 +111,7 @@ _findmnt_module()
                                --evaluate
                                --tab-file
                                --first-only
+                               --hyperlink
                                --invert
                                --json
                                --list
index f29f965421e658a96e5a55aa3db49606f718988e..23fb14da56a48e948418fe006e1a624e57a2a0e8 100644 (file)
@@ -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).
 
index 236e8e7a80f1ee2d2f41c774cbf3580259dfe138..736c20e03811be2b3cc9aef1841c9e8e0af959ab 100644 (file)
@@ -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
         */
index a8ebdea1c1de666647f7ffc58e035656ca80f075..5c74bddc4b2c8cf36bd1302fdaad345706a5536c 100644 (file)
@@ -39,6 +39,7 @@ struct findmnt {
        struct libmnt_cache *cache;
        unsigned int flags;
        int parse_nerrors;
+       char *uri;
        struct libscols_filter *filter;
 };