Live data from Hacker News

Clear Your Terminal in Style

adammusciano.com

81–90 of 133 posts

Re: Clear Your Terminal in Style

#81
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.

You don't know ctrl+L?

It looks like you're getting downvoted without explanation: Ctrl+L doesn't clear the scrollback, it just scrolls the terminal down.

Re: Clear Your Terminal in Style

#84
post #73
post #55

Earlier quoted context omitted.

I'm not 100% sure how ctrl+c (and ctrl+z) are handled but I do know they're edge cases because they're managed by the kernel and are not re-definable.

The terminal can optionally catch some characters and convert them to signals. By default, ^C sends SIGINT, ^\ sends SIGQUIT, and ^Z sends SIGTSTP. Programs can disable that for their own purposes (stty -isig) and you can rebind them to other characters if you want (stty intr, stty quit, stty susp) but I don't know why anyone would these days.

In Linux and UNIX you enable or disable use of ctrl+c (effectively setting the tty into a raw mode) via syscalls against the tty file descriptor - it is not handled by the terminal emulator at all (in fact if you read the man page for `stty` you'd see it's changing the your terminals fd and not the terminal emulator).

Sure, theoretically terminal emulators could capture and even rebind those keys via the APIs of whatever graphical toolkit they're built in....but if you wanted to rebind SIGINT to another key in the terminal emulator, that terminal emulator would still have to transmit ^c to the tty.

As for rebinding those keys in the kernel, Linux simply doesn't support doing that and nor does it support binding other keys to different signals. In fact I've tried to do this on a tool I was working on to emulate BSD's SIGINFO in Linux (turned out not to be possible) as as well part of the job control (SIGSTSP et al) support in my $SHELL (https://github.com/lmorg/murex).

This is also why you can throw signals over an SSH (or other remote shell) session when the terminal emulator itself would have no knowledge of the commands running on the remote host.

Re: Clear Your Terminal in Style

#86
In an average day I open more than 100 terminal windows (alt-escape which opens rxvt-unicode). Use most briefly, then they vanish behind other windows.

Every-so-often, when I get in a mess with alt-tab I run killUnusedTerminalsAndBC.sh, which kills the dozen or so bc instances that accumulate, and then kills any terminals which don't have anything running in them. I've done that a couple of times today, just did it again and killed another 10 hanging around. Most of the rest are idle, but sshed to other servers, so they don't get reaped.

Re: Clear Your Terminal in Style

#87

This one should really have a massive "do not try this": [ $[$RANDOM % 6] = 0 ] && sudo rm -rf / || echo "Not today" An awful lot of people just copy and paste things to see what'll happen.

I don't think it does. If one blindly copies a command to their terminal, this is a good lesson not to do so. Too many projects suggest `curl foo | sh` as the "quick and ready to go" method for installation which is equally as bad as rm -rf in the wild.

Re: Clear Your Terminal in Style

#88

This one should really have a massive "do not try this": [ $[$RANDOM % 6] = 0 ] && sudo rm -rf / || echo "Not today" An awful lot of people just copy and paste things to see what'll happen.

83% of them wouldn’t see any effect.

Unfortunately that might just compel them to keep trying.

Re: Clear Your Terminal in Style

#89
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.

printf "\033c"? I don't know if it resets, but it does clear the scroll buffer. I use it before compiling (printf "\033c"; make) so that I don't have to search for the first error or warning, I can just scroll all the way up.

On iTerm, that clears everything visible on the screen, but not the scroll history.

Sounds like your terminal clears everything? vt100 variants are a, uh, delightful mix of nearly-compatible dialects...

Post reply on HN