Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libsmartcols] watch vs tty column detection #1160

Closed
eMPee584 opened this issue Oct 9, 2020 · 2 comments
Closed

[libsmartcols] watch vs tty column detection #1160

eMPee584 opened this issue Oct 9, 2020 · 2 comments

Comments

@eMPee584
Copy link

eMPee584 commented Oct 9, 2020

Running lsblk under watch makes output overflow the terminal width; running outside of watch makes columns adjust appropriately.

watch -c -d -n 0.2 -- LIBSMARTCOLS_DEBUG_PADDING=on lsblk --paths \
--output VENDOR,MODEL,SERIAL,RO,RM,NAME,SIZE,FSUSE%,FSAVAIL,FSTYPE,LABEL,MOUNTPOINT,STATE

Use case: wanted to have a live view of plugged in USB pen drives (whilest flashing our https://schulstick.org/ ).. but some devices have insanely long serial numbers xD
insanely-long-serial-number_2020-10-09_20-09-34

@karelzak
Copy link
Collaborator

karelzak commented Oct 12, 2020

In this case, lsblk (and other tools) does not assume it's executed on the terminal and it does not restrict output and columns width. It's the same as "lsblk > file".

The ideal soution would be to improve watch(1) to execute commands in a own terminal (like script(1)), but it's not trivial ...

Anyway, you do not need watch(1) at all ;-), you can use bash loop + clear:

while true; do printf  "%${COLUMNS}s\n" "$(date)"; lsblk --paths \
  --output VENDOR,MODEL,SERIAL,RO,RM,NAME,SIZE,FSUSE%,FSAVAIL,FSTYPE,LABEL,MOUNTPOINT,STATE; sleep 0.2; clear; done

(the command printf is there only to provide date and demostrate it works).

For lsblk, we can add --output-width to restrict libsmartcols table formatting. I'll implement it as it seems usable in another use-cases too.

EDIT: I'll use --width to keep it shorter.

karelzak added a commit that referenced this issue Oct 12, 2020
Addresses: #1160
Signed-off-by: Karel Zak <kzak@redhat.com>
@eMPee584
Copy link
Author

A loop is ok – but watch does the difference highlighting 😎
Thanks for adding the option though. What a dream to-the-point-feature request delivery .. may the universe expand this pattern to all sentient programs, and may many more feature requests be fulfilled in this way. What a contrast to systemd style RESOLVED WONTFIX 👌😏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants