Live data from Hacker News

Clear Your Terminal in Style

adammusciano.com

21–30 of 133 posts

Re: Clear Your Terminal in Style

#21
post #17

I’d just settle for macOS’ Terminal.app’s ⌘-K, that resets the terminal, and clears all the screen including scroll back window. Something so basic I have it in muscle memory but I haven’t found the equivalent in Linux terminals.

I am currently using Fedora 31 Cinnamon which uses GNOME Terminal and the shortcut to reset and clear screen/scrollback is CTRL+L. I am not sure if this shortcut is standard on GNOME Terminal or not, but it's present in this flavor.

EDIT: On my windows machine I think it is ALT+F8 in Git Bash. May be similar in other terminal emulators.

Re: Clear Your Terminal in Style

#22
post #17

I’d just settle for macOS’ Terminal.app’s ⌘-K, that resets the terminal, and clears all the screen including scroll back window. Something so basic I have it in muscle memory but I haven’t found the equivalent in Linux terminals.

A lot of people swear by stuff like iTerm2, but I'm almost a little ashamed to admit that even though I have iTerm configured to my taste, I often still reach for macOS' native terminal. It's not gloriously beautiful or anything (basic Zsh with powerline for the shell), but it just seems to work great without the frills.

Little shortcuts that think of stuff like this without any configuration (iTerms is impressively extensive) are just a cherry on top. It kind of bums me out that's not linux native. Do you know of any other useful shortcuts specific to macOS? I've been using ctrl+L for the longest time. Thank you for sharing!

Re: Clear Your Terminal in Style

#23
post #12

I've just used alias c=clear in my .bashrc and never looked back. Not even Ctrl+L feels as convenient as c+Enter

> Ctrl+L feels as convenient as c+Enter I learned to hit Ctrl with my palms, and never looked back. Do you use your pinky? If so, I agree c+Enter is more convenient than ctrl+L.

It never even occurred to me to do that but trying it now, I don't think it's feasible for my hands. Either my palm mashes CTRL, ALT, and CMD (and sometimes FN and Shift) or I have a super awkward angle to get to the C key. It seems much easier to just drop my pinky down for half a second.

EDIT: After a suggestion from another user, I just remapped my Caps Lock to CTRL. That seems a lot easier to deal with. I'll try that for a bit and see how it goes.

Re: Clear Your Terminal in Style

#26

The square brackets for arithmetic conditionals in bash are deprecated. Rather than: [ $[$RANDOM % 10] = 0 ] ...you can use double-parentheses. Therein, you can omit the `$` on variables and, remember, the expression evaluates to true for any non-zero value. Thus, instead: (( RANDOM % 10 ))

You changed the probability here from 10% to 90% by inverting the test.

Re: Clear Your Terminal in Style

#27
post #26

The square brackets for arithmetic conditionals in bash are deprecated. Rather than: [ $[$RANDOM % 10] = 0 ] ...you can use double-parentheses. Therein, you can omit the `$` on variables and, remember, the expression evaluates to true for any non-zero value. Thus, instead: (( RANDOM % 10 ))

You changed the probability here from 10% to 90% by inverting the test.

True, you can just invert: alias clear='if ! (( RANDOM % 10 )); then timeout 3 cmatrix; clear; else clear; fi'

Re: Clear Your Terminal in Style

#29
post #17

I’d just settle for macOS’ Terminal.app’s ⌘-K, that resets the terminal, and clears all the screen including scroll back window. Something so basic I have it in muscle memory but I haven’t found the equivalent in Linux terminals.

I am currently using Fedora 31 Cinnamon which uses GNOME Terminal and the shortcut to reset and clear screen/scrollback is CTRL+L. I am not sure if this shortcut is standard on GNOME Terminal or not, but it's present in this flavor. EDIT: On my windows machine I think it is ALT+F8 in Git Bash. May be similar in other terminal emulators.

It's actually an Emacs keybinding, that was added to GNU readline, which is used by Bash; most shells followed suit (either by using readline, or implementing it themselves).

Ctrl + l is in Bash, in your case.

Re: Clear Your Terminal in Style

#30
post #7

I've just used alias c=clear in my .bashrc and never looked back. Not even Ctrl+L feels as convenient as c+Enter

the full monty: alias c='echo -e "\033c" ; stty sane; setterm -reset; reset; tput reset; clear' doesn't only clear the screen, but also escape any "broken" terminal configuration such as output of a binary on the tty

setterm does not work on macOS. I find reset(1) working fine. It already does clear, too.
Post reply on HN