commit - 2b650bbafb20bb7ab50ebf01fe8df71ac2b15466
commit + 0c961f7d3321f7810f6e45b6581762b5ed0fd2e1
blob - a02b9856bef290df3e828e9902cffaa26ac24240
blob + 8e50a14952c1ad2f7fede9fe4a9dd1a10efd62a3
--- ChangeLog.md
+++ ChangeLog.md
### Added
- Options:
- `-a` print all fields
+ - `-i` don't print fancy unicode characters
### Changed
- Merge "LABEL" and "MOUNT" fields into "LABEL/MOUNT"
because disks can't be mounted but partitions can,
and disks can have a label but partitions don't
(at least through the disklabel interface).
+- Print fancy unicode characters by default.
### Removed
- Options:
blob - 8e263e611381f89b75158489e87a707e66504496
blob + f554478425f50bfa22c7f7bdbc1be9b058aac0c6
--- README.md
+++ README.md
Workaround: `make unroot`
## TODO
-- [ ] Fancy unicodes: `├─` & `└─`
- [ ] `lsblk sd0`
blob - 947e92a5ce56e2605e5dd19c0016587a2b7fe4ca
blob + 2dfb9afa94e135119b69a482672e1fc6d8122f44
--- lsblk.8
+++ lsblk.8
.SH NAME
lsblk \- list block devices
.SH SYNOPSIS
-.B lsblk [-Valnu]
+.B lsblk [-Vainu]
.SH DESCRIPTION
The
.B lsblk
.B \-a
print all fields.
.TP
+.B \-i
+don't print fancy unicode characters, only print ASCII.
+.TP
.B \-n
don't print the header.
.TP
blob - 136f6741171ab966b7f00d656702373e038a37b3
blob + d23484030f2a1d2f549768a3c62824cb2926de70
--- lsblk.c
+++ lsblk.c
}
enum {
- FIELD_NAME = 0x01,
- FIELD_SIZE = 0x02,
- FIELD_USED = 0x04,
- FIELD_FREE = 0x08,
- FIELD_TYPE = 0x10,
- FIELD_LMNT = 0x20,
+ FIELD_NAME = 0x01,
+ FIELD_SIZE = 0x02,
+ FIELD_USED = 0x04,
+ FIELD_FREE = 0x08,
+ FIELD_TYPE = 0x10,
+ FIELD_LMNT = 0x20,
FIELD_DEFAULT = FIELD_NAME | FIELD_SIZE | FIELD_TYPE | FIELD_LMNT,
};
+enum {
+ OPT_NOHEADER = 0x01,
+ OPT_NOUNICODE = 0x02,
+};
+
struct my_partinfo {
char name[5];
uint64_t size;
putchar ('\n');
}
-static void print_part (const struct my_partinfo *part, int fields)
+static void print_part (const struct my_partinfo *part, int fields, int options, bool last)
{
- if (fields & FIELD_NAME)
- printf (" %s ", part->name);
+ if (fields & FIELD_NAME) {
+ const char *prefix = (options & OPT_NOUNICODE) ? " " : (last ? "└─" : "├─");
+ printf ("%s%s ", prefix, part->name);
+ }
if (fields & FIELD_SIZE)
print_size (part->size);
putchar ('\n');
}
-static void print_disk (const struct my_diskinfo *disk, int fields)
+static void print_disk (const struct my_diskinfo *disk, int fields, int options)
{
if (fields & FIELD_NAME)
printf ("%s ", disk->name);
putchar ('\n');
for (uint8_t i = 0; i < disk->num_parts; ++i)
- print_part (&disk->parts[i], fields);
+ print_part (&disk->parts[i], fields, options, i == (disk->num_parts - 1));
}
static const struct statfs *find_mount (const char *dev)
static int usage (void)
{
- fputs ("Usage: lsblk [-Vanu]\n", stderr);
+ fputs ("Usage: lsblk [-Vainu]\n", stderr);
return 1;
}
int main (int argc, char *argv[])
{
int option;
- bool header = true;
int fields = FIELD_DEFAULT;
+ int options = 0;
if (unveil ("/dev", "r") == -1)
die ("unveil(/dev)");
if (unveil (NULL, NULL) == -1)
die ("unveil()");
- while ((option = getopt (argc, argv, ":Vanu")) != -1) {
+ while ((option = getopt (argc, argv, ":Vainu")) != -1) {
switch (option) {
case 'V':
puts ("lsblk-" VERSION);
case 'a':
fields = -1;
break;
+ case 'i':
+ options |= OPT_NOUNICODE;
+ break;
case 'n':
- header = false;
+ options |= OPT_NOHEADER;
break;
case 'u':
fields |= FIELD_USED | FIELD_FREE;
free (names);
- if (header)
+ if (!(options & OPT_NOHEADER))
print_header (fields);
for (size_t i = 0; i < num_disks; ++i) {
- print_disk (&disks[i], fields);
+ print_disk (&disks[i], fields, options);
}
return 0;
}