CLI tool to insert spacers when command output stops
github.com
github.com
> The purpose of ets is similar to that of moreutils ts(1), but ets differentiates itself from similar offerings by running commands directly within ptys, hence solving thorny issues like pipe buffering and commands disabling color and interactive features when detecting a pipe as output. (ets does provide a reading-from-stdin mode if you insist.) ets also recognizes carriage return as a line seperator, so it doesn't choke if your command prints a progress bar. A more detailed comparison of ets and ts can be found below.
Edit: Maybe you should highlight the trailing pipe example (eg `ping localhost | grep icmp | ets`)? That is way more convenient to use than the introductory samples indicate. Being able to slap it onto the end of a pipeline I am developing feels less invasive than potentially have to quote my command for the sake of a debugging tool.
Also, I have to say, getting a 3D printer has definitely done this for things around the house. Every small niggle that used to fly under the radar and tolerated now has a tiny plastic thing fixing it once and for all.
awk -W interactive 'BEGIN { t = systime(); } { u=systime(); if (u - t > 1) { printf("= %s %ds =========\n",strftime("%T"), u - t); }; print $0; t = u; }'
Or if you want to clear the screen too awk -W interactive 'BEGIN { t = systime(); } { u=systime(); if (u - t > 1) { printf("\033[2J\033[H= %s %ds =========\n",strftime("%T"), u - t); }; print $0; t = u; }'Of course, I know it's a genuine hard area, and not one I've put any time into fixing, but it's also so high leverage--so many developers spend a ton of time in this environment.
https://askubuntu.com/questions/1467849/what-is-the-bar-on-t...
Also Konsole messes up its ansi states all the time. It’s the only terminal in which I can hit <up>, sometimes see “~[[A;” or similar after my prompt, hit <enter> and it actually executes the previous command.
oh maybe https://unix.stackexchange.com/questions/226731/jump-to-last... hmm - seems like the more searchable term is "prompt jumping"
iTerm also suppers showing the timestamp of each line, and it visualizes this in a nice way where lines emitted around the same time have their timestamps replaced with a vertical line.
Mine is not a tool, I just define my log function that tracks last call time.
const now = Date.now()
if (now - last_time >= 2000) {
console.log(…)
}
last_time = now
console.log(…args)
Things like that should be in all dev toolboxes by default, I think. It’s amazing how we create animated experiences etc for users but when it comes to development it’s just println(). The cobbler’s children go barefoot.- Years ago for timesheets, I created a "gap report" that finds when the gap between the last dated events exceeds a threshold.
- The vscode terminal indicates which stdout, stderr are from which process with a circle .
This says it's "Integrated > Shell Integration: Decorations Enabled" to configure the feature; https://stackoverflow.com/questions/73242939/vscode-remove-c...
- Are there other shells that indicate which stdout and stderr are from which process? What should it do about e.g. reset ANSI shell escape sequences?
PROMPT_COMMAND='_prev_status="$?"'
PS1='\n$(printf "%0${COLUMNS}d\n" 0 | tr 0 -)\n[\D{%y%m%d-%H%M%S}] \u@\H (${_prev_status})\n${PWD}\n\$ '
The first line saves the status of the previous command and the second line sets the prompt string.
The result is something like this: ---------------------------------------- <these dashes span the terminal width>
[date-time] user@host (status)
/current/working/directory
$ <next command>This tool might be nicer, but I’m not sure if know when I’d need to use it a priori.
I often press enter key a few times to produce a noticeable gap between different runs of the same command. Yes, in theory, the shell prompt is enough to separate the runs, and I could customize the color, font etc, but that's still not as good as a few (almost) blank lines.
The workflow is like this: often I need to run a command that produces a decent amount of output and repeat that a few times. Not 3 lines, not 1k lines, but something like 40-100 lines -- not short enough that I can easily see both the beginning and the end, not long enough that I have to log it to a file. I want to be able to scroll to the top of the output and read it.
The "multiple enter key" approach works well enough, but is a bit repetitive and sometimes I forget to do that (then can't find where the output begins). I could also append printf "\n\n\n" but apparently it's annoying. I wonder if there is something simpler and works well. The tool in this article doesn't exactly match my need, as it prints a spacer immediately after output pauses, not after a command finishes.
I’m not sure how it’s implemented… maybe they take note of what your prompt looks like and generate a regex for it? Or maybe they take note of when the last time it was that your shell process had no child processes and read from stdin… but it works quite reliably.
export PS1="\n\n\n\n\n\n$PS1"
Or if the repeated prompt is part of your visual pattern matching: export PS1="$PS1\n$PS1\n$PS1\n$PS1" # ~/.bashrc
alias p5='printf "\n\n\n\n\n"'
# run
my-command; p5
May also add 100 '-'s before or after newlines for better separation. alias p6='export PS1="\n\n\n\n\n\n$PS1"'
p6
my-command
my-commandYou can also collapse output too
$ --; make noisy-build
Then I can see the start easily when scrolling back.I found this comment in a bash documentation example to verify:
# To send stderr through a pipe, "|&" was added to Bash 4 as an abbreviation for "2>&1 |".
1. If a tool outputs escape sequences and expects the cursor to be at a certain position, this assumption will break 2. You have to not forget to pipe it, which might not always be possible to do cleanly 3. Since you're piping the output, many tools will stop using colours, etc, which is annoying.
I've tried to make a similar tool, but as a patch to bash (to color stderr output), and it had many issues that can't be resolved on that level, e.g. many programs assume that stderr and stdout point to the same PTY, so they can print some ascii sequences to stdout and some to stderr, and expect them to be displayed in the correct order. (The article about it, in Russian: https://habr.com/ru/articles/207768/)
[1]: https://wezfurlong.org/wezterm/config/lua/keyassignment/Scro...
(IIRC this is technically just a hotkey for navigating marks or bookmarks or something, and it (book)marks each command.
Your comment just makes you come off as some narrow-minded, graybeard elitist, and possibly even a little bit dumb, given how obvious it is why this could be useful. "New programmers", etc. Why not just .. not comment instead? Literally the easiest thing in the world for you to do since it requires you to do nothing.
For anyone who's interested, I recommend reading Julia Evan's article [2] about this problem and its solutions.
[0]: https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUN...
[1]: https://manpages.ubuntu.com/manpages/noble/man1/unbuffer.1.h...
[2]: https://jvns.ca/blog/2024/11/29/why-pipes-get-stuck-bufferin...
It's "Julia's article", not "The Julia article".
Update: it is was on here just a month ago actually: https://news.ycombinator.com/item?id=42275033
I don't know if Julia Evan even has an article.
Julia Evans's house, but the Evans' house.
(I consider myself a follower of Lynne Truss's, and have deliberately not considered a grammar reference for this answer, as I'm sure this is within the interested reader's ability and shan't spoil these readers' fun.)
On MacOS, can install via homebrew's `expect`: https://apple.stackexchange.com/a/193152/330523
Apparently I knew about this 2.5 years ago as I commented on the accepted answer back then.
BTW. Somewhat similiar (better sometimes) result can be achieved simply with:
(echo "first"; sleep 1; echo "second"; sleep 0.5; echo "third") | ts -i "%.S"
00.000004 first
00.987787 second
00.501363 third