diff options
| author | Karel Zak <kzak@redhat.com> | 2024-12-02 12:02:38 +0100 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2024-12-09 10:25:06 +0100 |
| commit | 5d0edf55b62f8f9ac9d58539014ea5c292df8291 (patch) | |
| tree | 91def32feb55fa5797802626fcbd4b8da3add6d9 | |
| parent | 8e54820c10a7e90316fc5e1abf52fbde9c4fd52d (diff) | |
| download | util-linux-5d0edf55b62f8f9ac9d58539014ea5c292df8291.tar.gz | |
lsblk: add --hyperlink command line option
Signed-off-by: Karel Zak <kzak@redhat.com>
| -rw-r--r-- | bash-completion/lsblk | 1 | ||||
| -rw-r--r-- | misc-utils/lsblk-mnt.c | 7 | ||||
| -rw-r--r-- | misc-utils/lsblk.8.adoc | 3 | ||||
| -rw-r--r-- | misc-utils/lsblk.c | 16 | ||||
| -rw-r--r-- | misc-utils/lsblk.h | 1 |
5 files changed, 26 insertions, 2 deletions
diff --git a/bash-completion/lsblk b/bash-completion/lsblk index 41c2b2c8fe..ff82685813 100644 --- a/bash-completion/lsblk +++ b/bash-completion/lsblk @@ -71,6 +71,7 @@ _lsblk_module() --fs --filter --highlight + --hyperlink --ct --ct-filter --help diff --git a/misc-utils/lsblk-mnt.c b/misc-utils/lsblk-mnt.c index 81ded5ea23..3217e3f554 100644 --- a/misc-utils/lsblk-mnt.c +++ b/misc-utils/lsblk-mnt.c @@ -64,6 +64,9 @@ static void add_filesystem(struct lsblk_device *dev, struct libmnt_fs *fs) dev->fss[dev->nfss] = fs; dev->nfss++; dev->is_mounted = 1; + + if (mnt_fs_is_swaparea(fs)) + dev->is_swap = 1; } struct libmnt_fs **lsblk_device_get_filesystems(struct lsblk_device *dev, size_t *n) @@ -162,8 +165,10 @@ const char *lsblk_device_get_mountpoint(struct lsblk_device *dev) } } } - if (mnt_fs_is_swaparea(fs)) + if (mnt_fs_is_swaparea(fs)) { + dev->is_swap = 1; return "[SWAP]"; + } return mnt_fs_get_target(fs); } diff --git a/misc-utils/lsblk.8.adoc b/misc-utils/lsblk.8.adoc index 308c71e3f6..d92d3fb44c 100644 --- a/misc-utils/lsblk.8.adoc +++ b/misc-utils/lsblk.8.adoc @@ -61,6 +61,9 @@ Exclude the devices specified by the comma-separated _list_ of major device numb *-f*, *--fs*:: Output info about filesystems. This option is equivalent to *-o NAME,FSTYPE,FSVER,LABEL,UUID,FSAVAIL,FSUSE%,MOUNTPOINTS*. The authoritative information about filesystems and raids is provided by the *blkid*(8) command. +*--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. + *-I*, *--include* _list_:: Include devices specified by the comma-separated _list_ of major device numbers. The filter is applied to the top-level devices only. This may be confusing for *--list* output format where hierarchy of the devices is not obvious. diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index cc1ae98b6c..6a8dc5011b 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -1274,10 +1274,14 @@ static void device_fill_scols_cell(struct lsblk_device *dev, ce = scols_line_get_cell(ln, colnum); if (!ce) return; + rc = datasiz ? scols_cell_refer_memory(ce, data, datasiz) : scols_cell_refer_data(ce, data); if (rc) err(EXIT_FAILURE, _("failed to add output data")); + + if (lsblk->uri && (id == COL_TARGETS || id == COL_TARGET) && dev->is_swap) + scols_cell_disable_uri(ce, 1); } static int filter_filler_cb( @@ -2407,7 +2411,8 @@ int main(int argc, char *argv[]) OPT_COUNTER_FILTER, OPT_COUNTER, OPT_HIGHLIGHT, - OPT_PROPERTIES_BY + OPT_PROPERTIES_BY, + OPT_HYPERLINK }; static const struct option longopts[] = { @@ -2424,6 +2429,7 @@ int main(int argc, char *argv[]) { "output-all", no_argument, NULL, 'O' }, { "filter", required_argument, NULL, 'Q' }, { "highlight", required_argument, NULL, OPT_HIGHLIGHT }, + { "hyperlink", optional_argument, NULL, OPT_HYPERLINK }, { "merge", no_argument, NULL, 'M' }, { "perms", no_argument, NULL, 'm' }, { "noheadings", no_argument, NULL, 'n' }, @@ -2667,6 +2673,11 @@ int main(int argc, char *argv[]) if (lsblk_set_properties_method(optarg) < 0) errtryhelp(EXIT_FAILURE); break; + case OPT_HYPERLINK: + if (hyperlinkwanted_or_err(optarg, + _("invalid hyperlink argument"))) + lsblk->uri = xgethosturi(NULL); + break; case 'H': collist = 1; break; @@ -2793,6 +2804,9 @@ int main(int argc, char *argv[]) if (fl & SCOLS_FL_WRAP) scols_column_set_wrapfunc(cl, NULL, scols_wrapzero_nextchunk, NULL); + if (lsblk->uri && (id == COL_TARGET || id == COL_TARGETS)) + scols_column_set_uri(cl, lsblk->uri); + set_column_type(ci, cl, fl); } diff --git a/misc-utils/lsblk.h b/misc-utils/lsblk.h index b2b9b40dcd..90d2df1a13 100644 --- a/misc-utils/lsblk.h +++ b/misc-utils/lsblk.h @@ -60,6 +60,7 @@ struct lsblk { size_t ncts; /* number of ct filters */ const char *sysroot; + char *uri; int flags; /* LSBLK_* */ int properties_by[__LSBLK_NMETHODS]; |
