TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

CLI tool to insert spacers when command output stops

257 点作者 freetonik5 个月前

22 条评论

zmw5 个月前
Related shameless plug: I have a small tool that prepends each output line with a timestamp (can be absolute, relative, or elapsed since last line), might be useful or pair well with this tool in similar scenarios (not needed when dealing with already timestamped logs, of course).<p><a href="https:&#x2F;&#x2F;github.com&#x2F;zmwangx&#x2F;ets">https:&#x2F;&#x2F;github.com&#x2F;zmwangx&#x2F;ets</a>
评论 #42495999 未加载
评论 #42496067 未加载
评论 #42498916 未加载
评论 #42495492 未加载
stavros5 个月前
I love it when someone has a problem I have very often, but they have the insight to actually <i>realize</i> that it&#x27;s a problem, and then do something about it.
评论 #42495084 未加载
评论 #42497950 未加载
overhead40755 个月前
A bit fancier than my awk version<p><pre><code> awk -W interactive &#x27;BEGIN { t = systime(); } { u=systime(); if (u - t &gt; 1) { printf(&quot;= %s %ds =========\n&quot;,strftime(&quot;%T&quot;), u - t); }; print $0; t = u; }&#x27; </code></pre> Or if you want to clear the screen too<p><pre><code> awk -W interactive &#x27;BEGIN { t = systime(); } { u=systime(); if (u - t &gt; 1) { printf(&quot;\033[2J\033[H= %s %ds =========\n&quot;,strftime(&quot;%T&quot;), u - t); }; print $0; t = u; }&#x27;</code></pre>
评论 #42505435 未加载
hyperpape5 个月前
It really never ceases to amaze me how many basic affordances terminals lack, that we hack around with bash configuration or helper tools.<p>Of course, I know it&#x27;s a genuine hard area, and not one I&#x27;ve put any time into fixing, but it&#x27;s also so high leverage--so many developers spend a ton of time in this environment.
评论 #42503608 未加载
评论 #42497015 未加载
评论 #42498271 未加载
评论 #42496894 未加载
评论 #42499046 未加载
wruza5 个月前
I often use this technique in my dev debug logs. If the last print() was more than a few seconds ago, it also prints “(2.4 seconds passed)” in gray text before printing another line. This helps with visually separating debug requests, button clicks, etc.<p>Mine is not a tool, I just define my log function that tracks last call time.<p><pre><code> const now = Date.now() if (now - last_time &gt;= 2000) { console.log(…) } last_time = now console.log(…args) </code></pre> 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.
westurner5 个月前
- In Python, Sarge has code to poll stdout and stderr<p>- Years ago for timesheets, I created a &quot;gap report&quot; that finds when the gap between the last dated events exceeds a threshold.<p>- The vscode terminal indicates which stdout, stderr are from which process with a circle .<p>This says it&#x27;s &quot;Integrated &gt; Shell Integration: Decorations Enabled&quot; to configure the feature; <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;73242939&#x2F;vscode-remove-circle-next-to-terminal" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;73242939&#x2F;vscode-remove-c...</a><p>- 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?
selendym5 个月前
In bash, you can do something like this out-of-the-box by setting the `PS1` variable to your liking. For example, I use the following in `&#x2F;etc&#x2F;bash.bashrc`:<p><pre><code> PROMPT_COMMAND=&#x27;_prev_status=&quot;$?&quot;&#x27; PS1=&#x27;\n$(printf &quot;%0${COLUMNS}d\n&quot; 0 | tr 0 -)\n[\D{%y%m%d-%H%M%S}] \u@\H (${_prev_status})\n${PWD}\n\$ &#x27; </code></pre> The first line saves the status of the previous command and the second line sets the prompt string. The result is something like this:<p><pre><code> ---------------------------------------- &lt;these dashes span the terminal width&gt; [date-time] user@host (status) &#x2F;current&#x2F;working&#x2F;directory $ &lt;next command&gt;</code></pre>
woodruffw5 个月前
Very nice! I’m one of those habitual return-pressers, and this tool accomplishes the exact same thing but better.
评论 #42495060 未加载
评论 #42496713 未加载
n144q5 个月前
I have a similar but different need, wonder if anyone has the same frustrations and knows a solution:<p>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&#x27;s still not as good as a few (almost) blank lines.<p>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.<p>The &quot;multiple enter key&quot; approach works well enough, but is a bit repetitive and sometimes I forget to do that (then can&#x27;t find where the output begins). I could also append printf &quot;\n\n\n&quot; but apparently it&#x27;s annoying. I wonder if there is something simpler and works well. The tool in this article doesn&#x27;t exactly match my need, as it prints a spacer immediately after output pauses, not after a command finishes.
评论 #42497618 未加载
评论 #42498825 未加载
评论 #42497866 未加载
评论 #42497990 未加载
评论 #42497659 未加载
评论 #42501520 未加载
评论 #42498442 未加载
Tsiklon5 个月前
As an aside I have foolishly never once thought that you could pipe both stdout and stderr to another program at the same time. You learn something new each day.
评论 #42494937 未加载
nasretdinov5 个月前
Nice tool, but I agree with other commenters that it needs to be implemented at the level of the terminal emulator (which makes it much harder to implement). The reasons for this are the following:<p>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&#x27;re piping the output, many tools will stop using colours, etc, which is annoying.<p>I&#x27;ve tried to make a similar tool, but as a patch to bash (to color stderr output), and it had many issues that can&#x27;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: <a href="https:&#x2F;&#x2F;habr.com&#x2F;ru&#x2F;articles&#x2F;207768&#x2F;" rel="nofollow">https:&#x2F;&#x2F;habr.com&#x2F;ru&#x2F;articles&#x2F;207768&#x2F;</a>)
forrestthewoods5 个月前
It drives me batty that terminals don’t have a trivial way to “scroll to last command”.
评论 #42497661 未加载
评论 #42497008 未加载
评论 #42497304 未加载
ezekg5 个月前
I wasn&#x27;t aware of |&amp; -- pretty sweet. I always redirected via 2&gt;&amp;1 and then piped.
oldetimeyunix5 个月前
I find it fascinating what new programmers prioritize. I’ve been developing on Unix and Unix like systems for 40 years and I’ve never needed a solution like this. But for some reason this appears to be a banger to some of you. Baffling but fascinating.
评论 #42497255 未加载
评论 #42498578 未加载
croemer5 个月前
When used with Python, it&#x27;s important to add &quot;PYTHONUNBUFFERED=1&quot; env variable for this to work not just in the terminal but also when piping to files etc.
评论 #42495619 未加载
kevincox5 个月前
I had the exact same problem and created a similar command with a slightly different strategy:<p><a href="https:&#x2F;&#x2F;gitlab.com&#x2F;kevincox&#x2F;watchlog&#x2F;-&#x2F;blob&#x2F;v1&#x2F;README.md" rel="nofollow">https:&#x2F;&#x2F;gitlab.com&#x2F;kevincox&#x2F;watchlog&#x2F;-&#x2F;blob&#x2F;v1&#x2F;README.md</a>
dpc_012345 个月前
Next level: Make it a wrapper `spacers ... cmd ...`. This way you can allocate PTY, and make the app believe it is still talking to the terminal and the use colors and alter its output in more fancy ways.<p>BTW. Somewhat similiar (better sometimes) result can be achieved simply with:<p>(echo &quot;first&quot;; sleep 1; echo &quot;second&quot;; sleep 0.5; echo &quot;third&quot;) | ts -i &quot;%.S&quot;<p>00.000004 first<p>00.987787 second<p>00.501363 third
jaimehrubiks5 个月前
I like it! but it would be even better as a shell&#x27;s plugin maybe?
renewiltord5 个月前
I also pipe to `ts` and successors since that gives me a running timer of when the last thing happened. It’s in moreutils.
JoBrad5 个月前
Wouldn’t putting a \n at the start of PS1 do a similar thing?
nerflad5 个月前
echo &quot;printf &#x27;\n&#x27;&quot; &gt;&gt; ~&#x2F;.config&#x2F;fish&#x2F;functions&#x2F;fish_right_prompt.fish....
tetris115 个月前
pretty cool idea, wish I had thought of it.