6 ms·
hr for your terminal
Tired of not finding things in your terminal because there's a lot of logs and garbage? Tired of destroying the Enter key by creating a "void zone" in your terminal so that you can see the error that you're trying to debug?
Use the old <hr /> tag, but in your terminal
- codegeek 13y agolove useful utilities like this. Nothing rocket science but handy. I updated the README.md btw and pull request already accepted. Thx :)
- C0d3r 13y agoThanks! This is actually what I love doing, small utilities to help me and others which are not that fancy but get the work done and are compatible with my workflow.
- chrisamiller 13y agoSimple and useful - thanks!
- yoha 13y agohr(){printf '=%.0s' $(seq $COLUMNS)}
- sp332 13y agoWhat language is that?
- sdfjkl 13y agozsh
- sheetjs 13y agobash shell, although some whitespace is missing: hr() { printf '=%.0s' $(seq $COLUMNS); } printf is a bash builtin
- ajross 13y agoActually printf is a POSIX standard shell utility. Bash happens to implement it as a builtin, but there's also a conforming copy in GNU coreutils (and presumably busybox, but I didn't check). And the syntax above is standard Bourne shell, not specifically bash. Actually of the constructs in that, the only non-portable one is the seq tool, which (I think) is unique to coreutils.
- sheetjs 13y agoI don't know if its still the case, but OSX used to not ship with seq. Instead, you had to use jot.
- _delirium 13y agoOSX 10.9 ships a 'seq'. This particular version was written in 2005 by the NetBSD project, and its provenance is NetBSD 3.0 -> FreeBSD 9.0 -> OSX. Fwiw, it isn't a GNUism, though GNU's version was the first widely distributed one. A 'seq' appears in some old Research UNIX editions, and also in Plan9, but not in commercial AT&T Unix or in BSD. Instead 'jot' is the traditional BSD utility. Not sure if commercial AT&T Unix (and descendants) had anything similar.
- azinman2 13y agonice and simple! added to my .zshrc :)
- antimora 13y agoHere is a copy-n-paste to your bash prompt: function hr { printf '=%.0s' $(seq $COLUMNS); }
- rcfox 13y agoAnyone know how to add this sort of thing before the prompt in `git add -p` ?
- C0d3r 13y agoYou can create an alias in git like this: vim ~/.gitconfig ap = !hr && git add -p # Add this line to your file
- IgorPartola 13y agoGreat idea, one random nitpick: curl https://raw.github.com/LuRsT/hr/master/hr > ~/bin/hr is just evil. That'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.
- C0d3r 13y agoI know that, I did not want to be evil writing that in the instructions but that's the best way to copy that file, also this is a file to be executable, so even if you use wget you are asking for trouble, downloading a file to your $PATH and making it executable, do you have any idea on how to improve the instructions?
- IgorPartola 13y agoI honestly don't know of another way, other than encouraging the user to read the code.
- mattgreenrocks 13y agoMake a Homebrew version :)
- vezzy-fnord 13y agoPractical example: http://russianroulette.sh http://russianroulette.sh
- bodyfour 13y agoHow is it worse than: $ ./configure && make I guarantee you that it'd be easier to hide something nefarious in 3000 lines of autoconf boilerplate.
- IgorPartola 13y agoIt's not. And at least the download here is over HTTPS, not HTTP. But you are right, both are vulnerable unless the user is ready to be cautious.
- middleclick 13y agoNice and useful! Thanks!
- NickSharp 13y agoLove it. Thanks!
- loopj 13y agoI currently just mash <return> <return> <return> to create a visual break in my terminal output.
- C0d3r 13y agoMe too, and it's exactly why I made this script :)
- comex 13y agoSome other characters you may want to substitute into the script: ―――――――――――――――――――――――――――――――――――――――――――――――――― ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅ ██████████████████████████████████████████████████
- C0d3r 13y agoOh yeah! Definitely! Although, to make this non-unicode compatible, it's better to have a cleaner default like '='. But if you really want another character by default, you can do this: alias hr='hr █'
- roadnottaken 13y agoLove this, thanks!
- tgrochowicz 13y agoi forked this to do something immature instead because i'm 12 years old. $ dong 8=================================D # Till the end of your terminal window $ https://github.com/tgrochowicz/hr https://github.com/tgrochowicz/hr
- jamestomasino 13y agoGreat little script. I tossed it into by bash functions and added a bit of error checking and output formatting: https://github.com/jamestomasino/bash-scripts/blob/master/.functions#L159-L174 https://github.com/jamestomasino/bash-scripts/blob/master/.f...
- Aardwolf 13y agoMuch simpler: having a colored prompt works quite well to solve the mentioned problem. PS1="\[\033[0;31m\][\u@\h:\w]$\[\033[0m\]"
- wylee 13y agoI just stuck this in my PS1: hr() { printf '=%.0s' $(seq $((${COLUMNS} - 20))) } PS1="${GREY}\d ${RED}\$(hr)${GREY} \t" It dynamically adjusts to the width of the terminal, and looks like this: Mon Feb 10 ======================================== 16:30:30 My complete BASH prompt: https://bitbucket.org/wyatt/dotfiles/src/25cb260a05b68dd81a5c8710b5034a0b08ea9a81/bashrc?at=default#cl-47 https://bitbucket.org/wyatt/dotfiles/src/25cb260a05b68dd81a5...
- jethro_tell 13y agoOr a colored prompt with a timestamp and hostname, great with a huge scrollback. PS1='\[\033[1;32m\](\A) <\h> [$PWD \$ \[\033[m\]' Edit: Using tmux with a 200,000 line scrollback, you can also search scrollback based on the hour in which you ran the command. A search for "(12:" would put you right in the ball park.
- abruzzi 13y agoThe one problem is that the ability or substitute a different character doesn't test for length. I want to do: hr --==##==
- deleted 13y ago[deleted]
- num 13y agoFortunately this is what I've used Figlet (http://www.figlet.org http://www.figlet.org) or Toilet (http://caca.zoy.org/wiki/toilet http://caca.zoy.org/wiki/toilet) for: $ figlet -- ---------- _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ |_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|
- pbhjpbhj 13y agoI'm interested why they use "seq"? [seq can take a single value too apparently, perhaps they did half width rulers with "seq 2 $(tputs cols)"?] Why doesn't !/bin/bash j=$(tput cols); for i in {1..$j}; do echo -n "#";done work, presumably there's some escape that needs doing? The alternative: !/bin/bash for (( c=1 ; c<=$COLUMNS; c++ )); do echo -n "#";done seems fine? Also BASH has $COLUMNS builtin FWIW, though portability explains use of tput. 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.
- pdw 13y agoBoth of those would work in bash, but they're non-standard extensions. The seq construction would work in any POSIX shell, though the seq command itself is still non-standard I think.
- pbhjpbhj 13y agoSorry, the first doesn't work - I was asking if anyone knew why. The second works in BASH, but it's bashism as you note.
- deleted 13y ago[deleted]
- ehamberg 13y agoIf you want a solid line, you could use U+2501 (━) from the set of box drawing characters (https://en.wikipedia.org/wiki/Box-drawing_character https://en.wikipedia.org/wiki/Box-drawing_character): <━> 9473, U+2501 BOX DRAWINGS HEAVY HORIZONTAL hr(){printf '━%.0s' $(seq $COLUMNS)}
- ppurka 13y agoIndeed, printf is shorter. I use it in a similar fashion in my own script [1], which can be made to behave like hr() (haven't tried shells other than bash): centered_output '=' '' [1] https://github.com/ppurka/sh_functions/blob/master/my_bash_functions#L97 https://github.com/ppurka/sh_functions/blob/master/my_bash_f...
- thekaleb 13y agoAnd now it works in the bourne shell!
- Fasebook 13y agoIf you want to conform to ANSI, just use two dashes (--) or ASCII, the box drawing character, the source of the unicode variant. This is important because it remains the primary font in the core of any EGA and VGA-compatible graphics card (basically all graphics cards).
- chjj 13y agoSome terminals support ACS (with SCLD) but not unicode. It might be better to use ACS: $ hr() { printf '\e(0'; printf 'q%.0s' $(seq $(tput cols)); printf '\e(B'; } Same thing, but potentially more portable. edit: Could also use tput instead of $COLUMNS. Sometimes the $COLUMNS may not always be updated (bash's checkwinsize option).
- nagrom 13y agoI don't understand - is there something better about this than the 'clear' command?
- Ujio 13y agoClear doesn't do anything to differentiate new output from old.
- nagrom 13y agoIt makes an entire blank line, which is sufficient if you have a lot of textual output. It also gets rid of the old stuff from the screen - if you're running a window manager, you can then scroll up if you need the old stuff.
- C0d3r 13y agoI use `clear` but in tmux, the whitespace produced by `clear` disappears, so it's the same as pressing <Enter> :(
- ramses0 13y agoI like to use terminal colors so it's red, as well as allowing controlling width, but defaulting to terminal width. $ cat ~/bin/br #!/bin/sh if [ "$1" == "" ] ; then COLS=`tput cols` elif [ "$1" == "--help" ] ; then echo "$0: Prints a red line across the screen. or $0 <##> for a specific width." echo "$0: br ; grep -ir foo * -- place a marker to see where results begin / end." echo "$0: br 80 ; cat file -- use to check for overly long lines." exit else COLS=$1 fi LINE="" for (( x=0 ; x<$COLS ; x++ )); do LINE="$LINE-" ; done echo -e '\E[47;0m'"\033[1m$LINE\033[0m"
- deleted 13y ago[deleted]
- lstamour 13y agoThis has me wondering, why haven't terminal windows evolved functionally to better support history, scrollback buffers jumping or markers, selection with a mouse, auto-complete hints, etc. Instead we're limited to hacks like this or the screenshot at http://unix.stackexchange.com/questions/3650/would-it-be-possible-to-jump-between-prev-next-command-prompts http://unix.stackexchange.com/questions/3650/would-it-be-pos... ... and no, I don't think "use emacs" is an acceptable answer ;-) Oh and instead of adding blank lines with "Enter", I often just type "clear" and hit return. Bingo, tons of whitespace now added.
- ppurka 13y agoI think terminology [1] is quite promising, although it doesn't yet do all of the above. [1] http://www.enlightenment.org/p.php?p=about/terminology http://www.enlightenment.org/p.php?p=about/terminology
- lstamour 13y agoHuh. From there I discovered http://acko.net/blog/on-termkit/ http://acko.net/blog/on-termkit/ Previous thread: https://news.ycombinator.com/item?id=2559734 https://news.ycombinator.com/item?id=2559734 Related terminals: https://news.ycombinator.com/item?id=3227702 https://news.ycombinator.com/item?id=3227702 https://news.ycombinator.com/item?id=3910649 https://news.ycombinator.com/item?id=3910649 "What happened to TermKit?" on Reddit with a reply from the author: http://www.reddit.com/r/programming/comments/137kd9/18_months_ago_termkit_a_nextgeneration_terminal/ http://www.reddit.com/r/programming/comments/137kd9/18_month... I'm thinking we'll need a terminal window that interfaces with bash but has overlays in HTML and other controls for scrollback, etc. Maybe a fork of an existing terminal.
- C0d3r 13y agoI use clear too, far too often, but with tmux, when you scroll up, you don't get the tons of whitespace that you get with just the terminal :(
- datr 13y agoI've often wondered if there is a terminal which supported the "jump to previous input" functionality described in the stackexchange question but I've never seen anything better than what is mentioned in the answers. I've heard Plan 9's Rio supported something like this but searching around, I can't see any mention of it.
- gamacodre 13y agoIf you like this idea and are stuck in Windows, this does the same thing: @set @jScript=1;/* @for /f "tokens=1,2" %%w in ('mode con:') do @if "%%w" == "Columns:" set cols=%%x @cscript /noLogo /E:jScript "%~f0" %cols% %1 = @Goto :EOF */line='';while(line.length<WScript.Arguments(0))line+=WScript.Arguments(1); WScript.StdOut.Write(line.substr(0,WScript.Arguments(0))); Save as hr.cmd and stick it somewhere in your path.
- KiwiCoder 13y agoPerl on Windows; perl -e "$_=`mode`;/ns:\s+(\d+)/;print '='x$1"
- farginay 13y agoI've long wanted a shell with logical separation of each command/output pair.
- hayksaakian 13y agoI thought control + l was a fairly well known hotkey? it inserts a terminal worth of line breaks
- chris-martin 13y agoPS1="$(hr -) $PS1" Beautiful. Now I need a way to make this happen in SBT too.