TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

hr for your terminal

82 pointsby C0d3rover 11 years ago
Tired of not finding things in your terminal because there&#x27;s a lot of logs and garbage? Tired of destroying the Enter key by creating a &quot;void zone&quot; in your terminal so that you can see the error that you&#x27;re trying to debug?<p>Use the old &lt;hr &#x2F;&gt; tag, but in your terminal

24 comments

ehambergover 11 years ago
If you want a solid line, you could use U+2501 (━) from the set of box drawing characters (<a href="https://en.wikipedia.org/wiki/Box-drawing_character" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Box-drawing_character</a>):<p><pre><code> &lt;━&gt; 9473, U+2501 BOX DRAWINGS HEAVY HORIZONTAL hr(){printf &#x27;━%.0s&#x27; $(seq $COLUMNS)}</code></pre>
评论 #7215013 未加载
评论 #7214413 未加载
评论 #7214202 未加载
评论 #7214251 未加载
IgorPartolaover 11 years ago
Great idea, one random nitpick:<p><pre><code> curl https:&#x2F;&#x2F;raw.github.com&#x2F;LuRsT&#x2F;hr&#x2F;master&#x2F;hr &gt; ~&#x2F;bin&#x2F;hr </code></pre> is just evil. That&#x27;s a great way to own a machine. You can even read the code today, but run the command tomorrow when someone had replaced the code with a giant exploit. Not saying there is a better way to distribute something like this that is as easy to use, but damn, this is just asking for trouble.
评论 #7213563 未加载
评论 #7213757 未加载
评论 #7213570 未加载
评论 #7214059 未加载
评论 #7213551 未加载
评论 #7213554 未加载
评论 #7214309 未加载
lstamourover 11 years ago
This has me wondering, why haven&#x27;t terminal windows evolved functionally to better support history, scrollback buffers jumping or markers, selection with a mouse, auto-complete hints, etc. Instead we&#x27;re limited to hacks like this or the screenshot at <a href="http://unix.stackexchange.com/questions/3650/would-it-be-possible-to-jump-between-prev-next-command-prompts" rel="nofollow">http:&#x2F;&#x2F;unix.stackexchange.com&#x2F;questions&#x2F;3650&#x2F;would-it-be-pos...</a> ... and no, I don&#x27;t think &quot;use emacs&quot; is an acceptable answer ;-)<p>Oh and instead of adding blank lines with &quot;Enter&quot;, I often just type &quot;clear&quot; and hit return. Bingo, tons of whitespace now added.
评论 #7220496 未加载
评论 #7214370 未加载
评论 #7214988 未加载
评论 #7214138 未加载
tgrochowiczover 11 years ago
i forked this to do something immature instead because i&#x27;m 12 years old.<p>$ dong 8=================================D # Till the end of your terminal window $<p><a href="https://github.com/tgrochowicz/hr" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tgrochowicz&#x2F;hr</a>
评论 #7213863 未加载
评论 #7214057 未加载
loopjover 11 years ago
I currently just mash &lt;return&gt; &lt;return&gt; &lt;return&gt; to create a visual break in my terminal output.
评论 #7213553 未加载
comexover 11 years ago
Some other characters you may want to substitute into the script:<p>――――――――――――――――――――――――――――――――――――――――――――――――――<p>━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<p>┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅<p>██████████████████████████████████████████████████
评论 #7213590 未加载
Aardwolfover 11 years ago
Much simpler: having a colored prompt works quite well to solve the mentioned problem.<p>PS1=&quot;\[\033[0;31m\][\u@\h:\w]$\[\033[0m\]&quot;
评论 #7214867 未加载
评论 #7214127 未加载
jamestomasinoover 11 years ago
Great little script. I tossed it into by bash functions and added a bit of error checking and output formatting: <a href="https://github.com/jamestomasino/bash-scripts/blob/master/.functions#L159-L174" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jamestomasino&#x2F;bash-scripts&#x2F;blob&#x2F;master&#x2F;.f...</a>
ramses0over 11 years ago
I like to use terminal colors so it&#x27;s red, as well as allowing controlling width, but defaulting to terminal width.<p><pre><code> $ cat ~&#x2F;bin&#x2F;br #!&#x2F;bin&#x2F;sh if [ &quot;$1&quot; == &quot;&quot; ] ; then COLS=`tput cols` elif [ &quot;$1&quot; == &quot;--help&quot; ] ; then echo &quot;$0: Prints a red line across the screen. or $0 &lt;##&gt; for a specific width.&quot; echo &quot;$0: br ; grep -ir foo * -- place a marker to see where results begin &#x2F; end.&quot; echo &quot;$0: br 80 ; cat file -- use to check for overly long lines.&quot; exit else COLS=$1 fi LINE=&quot;&quot; for (( x=0 ; x&lt;$COLS ; x++ )); do LINE=&quot;$LINE-&quot; ; done echo -e &#x27;\E[47;0m&#x27;&quot;\033[1m$LINE\033[0m&quot;</code></pre>
pbhjpbhjover 11 years ago
I&#x27;m interested why they use &quot;seq&quot;? [seq can take a single value too apparently, perhaps they did half width rulers with &quot;seq 2 $(tputs cols)&quot;?]<p>Why doesn&#x27;t<p><pre><code> !&#x2F;bin&#x2F;bash j=$(tput cols); for i in {1..$j}; do echo -n &quot;#&quot;;done </code></pre> work, presumably there&#x27;s some escape that needs doing?<p>The alternative:<p><pre><code> !&#x2F;bin&#x2F;bash for (( c=1 ; c&lt;=$COLUMNS; c++ )); do echo -n &quot;#&quot;;done </code></pre> seems fine?<p>Also BASH has $COLUMNS builtin FWIW, though portability explains use of tput.<p>I like it, should be a standard command, including options to specify width as a proportion and to add whitespace lines. Code for this must be in almost every shell script.
评论 #7214716 未加载
yohaover 11 years ago
hr(){printf &#x27;=%.0s&#x27; $(seq $COLUMNS)}
评论 #7213538 未加载
评论 #7213509 未加载
评论 #7213511 未加载
gamacodreover 11 years ago
If you like this idea and are stuck in Windows, this does the same thing:<p><pre><code> @set @jScript=1;&#x2F;* @for &#x2F;f &quot;tokens=1,2&quot; %%w in (&#x27;mode con:&#x27;) do @if &quot;%%w&quot; == &quot;Columns:&quot; set cols=%%x @cscript &#x2F;noLogo &#x2F;E:jScript &quot;%~f0&quot; %cols% %1 = @Goto :EOF *&#x2F;line=&#x27;&#x27;;while(line.length&lt;WScript.Arguments(0))line+=WScript.Arguments(1); WScript.StdOut.Write(line.substr(0,WScript.Arguments(0))); </code></pre> Save as hr.cmd and stick it somewhere in your path.
numover 11 years ago
Fortunately this is what I&#x27;ve used Figlet (<a href="http://www.figlet.org" rel="nofollow">http:&#x2F;&#x2F;www.figlet.org</a>) or Toilet (<a href="http://caca.zoy.org/wiki/toilet" rel="nofollow">http:&#x2F;&#x2F;caca.zoy.org&#x2F;wiki&#x2F;toilet</a>) for:<p><pre><code> $ figlet -- ---------- _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ |_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|</code></pre>
codegeekover 11 years ago
love useful utilities like this. Nothing rocket science but handy. I updated the README.md btw and pull request already accepted. Thx :)
评论 #7213484 未加载
评论 #7213494 未加载
nagromover 11 years ago
I don&#x27;t understand - is there something better about this than the &#x27;clear&#x27; command?
评论 #7213926 未加载
rcfoxover 11 years ago
Anyone know how to add this sort of thing before the prompt in `git add -p` ?
评论 #7213531 未加载
abruzziover 11 years ago
The one problem is that the ability or substitute a different character doesn&#x27;t test for length. I want to do: hr --==##==
评论 #7216380 未加载
评论 #7214205 未加载
评论 #7213742 未加载
KiwiCoderover 11 years ago
Perl on Windows;<p><pre><code> perl -e &quot;$_=`mode`;&#x2F;ns:\s+(\d+)&#x2F;;print &#x27;=&#x27;x$1&quot;</code></pre>
farginayover 11 years ago
I&#x27;ve long wanted a shell with logical separation of each command&#x2F;output pair.
hayksaakianover 11 years ago
I thought control + l was a fairly well known hotkey?<p>it inserts a terminal worth of line breaks
chris-martinover 11 years ago
PS1=&quot;$(hr -) $PS1&quot;<p>Beautiful.<p>Now I need a way to make this happen in SBT too.
middleclickover 11 years ago
Nice and useful! Thanks!
roadnottakenover 11 years ago
Love this, thanks!
NickSharpover 11 years ago
Love it. Thanks!