News for hackers. Stuff that matters.
Re:Clear Your Terminal in Style by fmajid on Thursday March 05, 2020 @08:55AM (#22493478)
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.
Re:Clear Your Terminal in Style by CSSer on Thursday March 05, 2020 @09:21AM (#22493675)
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 by yodsanklai on Thursday March 05, 2020 @01:58PM (#22496788)
> A lot of people swear by stuff like iTerm2

Actually, I've been using Terminal for years. I usually try to use default apps as much as possible (Safari, Mail, Notes, Terminal) to reduce configuration overhead. I switched to iTerm2 a few days ago after reading an article on HN... not sure if it worth the change, but haven't tried anything fancy yet. What would be the killer feature of iTerm2?

Re:Clear Your Terminal in Style by senordevnyc on Thursday March 05, 2020 @09:06PM (#22500421)
Drop down with global shortcut (I use control + ‘)

https://www.marcjenkins.co.uk/drop-down-terminal-with-iterm2...

Re:Clear Your Terminal in Style by kmundnic on Thursday March 05, 2020 @02:14PM (#22496982)
For me it is its integration with tmux, and therefore being able to use the command line in a remote computer as if you were using it locally.
Re:Clear Your Terminal in Style by gumby on Thursday March 05, 2020 @03:57PM (#22498139)
I just use tramp for this.
Re:Clear Your Terminal in Style by hanley on Thursday March 05, 2020 @03:46PM (#22498011)
I use profile triggers to change the color scheme of the shell when I SSH to a production server. The color I chose is different from my regular scheme so that it reminds me I am in production and things can break if I'm not careful.
Re:Clear Your Terminal in Style by pdpi on Thursday March 05, 2020 @04:05PM (#22498248)
I'm sort of in the opposite camp — I remember there being a non-trivial reason for moving over to iTerm several years ago, but now it's just become a habit and I can't for the life of me remember why I'm using it still.

As for shortcuts — ctrl-K (kill line), ctrl-A (go to start of line), ctrl-E (end of line) are my bread and butter, and work with most shells.

Re:Clear Your Terminal in Style by saalweachter on Thursday March 05, 2020 @04:19PM (#22498412)
One thing I loved about Macs, even though I haven't used one in years, was that you could use Emacs keybindings with the control key and "standard" keybindings with the command key. Being able to type both C-c and ⌘-c was nice.
Re:Clear Your Terminal in Style by pdpi on Thursday March 05, 2020 @06:25PM (#22499503)
Definitely, having readline shortcuts available more or less across the whole OS is a godsend.
Re:Clear Your Terminal in Style by Flow on Thursday March 05, 2020 @12:09PM (#22495528)
Since cmd+<number> now switches tab in Terminal.app, and the other few things I like, such as remembering the scrollbacks, number of tabs and cwd's, I find I have no use of iTerm2 any longer.

Plus, Terminal.app feels much faster. Using terminal Emacs feels very different in the two terminals.

Re:Clear Your Terminal in Style by reaperducer on Thursday March 05, 2020 @05:23PM (#22498982)
Plus, Terminal.app feels much faster. Using terminal Emacs feels very different in the two terminals.

I recently switched back to Terminal from iTerm, and was amazed by the speed increase.

When entering commands, it is visibly a little "snappier." But where it really shines is in the output.

I have a few of batch processes that I have to run once a week, and they're all pretty heavy on the debug output, with lots of VT100 eye candy. One process that used to take close to six hours in iTerm got significantly shaved when I switched to Terminal.

Since I only run this once a week, I haven't had a chance to benchmark it, but my guess is that Terminal shaved 40 minutes off the job.

The only thing I miss from iTerm is having two sessions open in a single window. I suspect this is possible in Terminal, but I haven't figured it out yet. When I click the "Split Pane" button, I get two panes of the same session, instead of a new session in the new pane.

Re:Clear Your Terminal in Style by oefrha on Thursday March 05, 2020 @10:12AM (#22494127)
The fact that Ternimal.app and iTerm2 use different keyboard shortcuts for clearing scrollback buffer (⌥⌘K vs ⇧⌘K) is a constant frustration of my spotty use of Terminal.app. I would instinctively hit the iTerm2 shortcut, which brings up a connect to server panel or something.
Re:Clear Your Terminal in Style by makecheck on Thursday March 05, 2020 @10:15AM (#22494162)
You can use System Preferences (Keyboard -> Shortcuts, “App Shortcuts” in the list) to change any binding in any menu item in any app. In this case you could force both apps to use the same keys for those commands.
Re:Clear Your Terminal in Style by oefrha on Thursday March 05, 2020 @11:12AM (#22494794)
Good point. I used that feature in the past but somehow haven’t touched it in years.
Re:Clear Your Terminal in Style by CUViper on Thursday March 05, 2020 @07:39PM (#22500027)
> The fact that Ternimal.app

That typo has a nice program of its own: https://github.com/p-e-w/ternimal

Re:Clear Your Terminal in Style by balladeer on Thursday March 05, 2020 @07:38PM (#22500023)
I don’t even install any other terminal. I just update bash to latest and stick to stock terminal. I have come to believe that often tool overload adds to the clutter and complexity and problems that didn’t need solving in the first place.
Re:Clear Your Terminal in Style by capn_cabbage on Thursday March 05, 2020 @09:20AM (#22493665)
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 by jerf on Thursday March 05, 2020 @12:32PM (#22495794)
CTRL-l is a standard "clear the screen" keystroke, and should work in all terminals, but it does not necessarily clear the scrollback buffer. Since "scrollback" is something implemented by the emulator itself, you'll have to look up how to do it there.

I use konsole, and it's CTRL-SHIFT-k there by default, I believe. I just ran gnome-terminal, and I see in Edit -> Preferences -> Terminal -> Reset and Clear that you can give it a shortcut key but it does not appear to ship with one configured by default.

Re:Clear Your Terminal in Style by djsumdog on Thursday March 05, 2020 @02:32PM (#22497192)
The reset command should clear the scrollback buffer. On older terminals where you'd get a garbled screen if you accidentally cat a binary file, it will give you your ASCII back.
Re:Clear Your Terminal in Style by jerf on Thursday March 05, 2020 @04:41PM (#22498661)
Trying it just now on konsole, it does not. Whether that's because your terminal is following standards or because your terminal is interpreting a terminal command that doesn't actually say anything about scrollback to also clear scrollback, I don't know, and await anyone who does to answer that question.

My gut is that the terminal protocol would know nothing about scrollback and thus not have a "clear scrollback" command in it directly. There are plenty of other indications that scrollback is basically a hack.

Re:Clear Your Terminal in Style by gerdesj on Thursday March 05, 2020 @05:38PM (#22499116)
[Konsole] Settings -> Configure Keyboard Shortcuts ... "Clear Scrollback and Reset". On my Arch boxes it is mapped to Ctrl + Shift + k. That's probably a default from upstream.
Re:Clear Your Terminal in Style by scrollaway on Thursday March 05, 2020 @04:57PM (#22498788)
Tried it on konsole 19.12.2 (on Arch), it works for me.
Re:Clear Your Terminal in Style by JdeBP on Friday March 06, 2020 @10:24AM (#22504250)
Your "gut" is wrong. It's ED 3.
Re:Clear Your Terminal in Style by runlevel1 on Friday March 06, 2020 @11:45AM (#22505014)
It's a common feature, but not formally standardized.

ED 3 isn't actually in the [ECMA-048] spec.

It was an xterm feature introduced in June 1999. Several terminal developers later adopted the feature. In April 2011, a Red Hat developer submitted a patch to the Linux kernel, modifying its console driver to do the same thing.

So it's not a formal standard, but it's universal on Linux since 3.0 and many terminal emulators have adopted it.

This history is covered in [clear(1)] from the ncurses project.

[ECMA-48]: http://www.ecma-international.org/publications/files/ECMA-ST...

[clear(1)]: http://man7.org/linux/man-pages/man1/clear.1.html#HISTORY

EDIT: Fix wording and formatting.

Re:Clear Your Terminal in Style by JdeBP on Saturday March 07, 2020 @10:47AM (#22512114)
... none of which contradicts the point that the protocol does know about scrollback. The aforementioned developer, Petr Písař, got the implementation wrong, note.

* https://unix.stackexchange.com/a/375784/5132

* http://jdebp.uk./Softwares/nosh/guide/commands/setterm.xml

Re:Clear Your Terminal in Style by swiley on Thursday March 05, 2020 @03:59PM (#22498172)
Reset takes at least a couple seconds though, I’m not sure I’d swap it with clear in something like:

    clear && make test
Re:Clear Your Terminal in Style by capn_cabbage on Thursday March 05, 2020 @01:09PM (#22496233)
I may have changed the key binding after installation. It has been a while so it feels like it has always been that way.
Re:Clear Your Terminal in Style by microcolonel on Thursday March 05, 2020 @10:01AM (#22494030)
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 by LukeShu on Thursday March 05, 2020 @11:04AM (#22494707)
While many of the readline keybindings come from Emacs, I would have said the common shell handling of Ctrl-L comes from that ^L is ASCII form-feed, which is "clear the page; start a new page" (in the same way that ^H is ASCII backspace).

I hadn't considered Bash C-L to be the same as Emacs C-L, since in Emacs I can hit C-L again to "undo" it (kinda).

Re:Clear Your Terminal in Style by OrderlyTiamat on Thursday March 05, 2020 @05:42PM (#22499145)
C-l doesn't clear anything in it's default behavior right? It changes the line-at-poit to be at the center of the screen, bottom, or top, depending on how often yoi press it.

I would never have associated that with screen clear.

E: excuse me, of course C-l does the same scrolling in the terminal, it doesn't clear the history of course.

Re:Clear Your Terminal in Style by Tyr42 on Thursday March 05, 2020 @09:06AM (#22493555)
It's also super helpful when you want to run one command which spews out a bunch of errors, and then read the first error. Cmd-K, enter, and fling up the the trackpad. I think I'd have to pipe to less if I don't have cmd-K.
Re:Clear Your Terminal in Style by bobbylarrybobby on Thursday March 05, 2020 @10:18AM (#22494195)
Cmd up and down navigates between prompts, so you don’t even have to scroll
Re:Clear Your Terminal in Style by brigandish on Thursday March 05, 2020 @10:27AM (#22494277)
I tried this and it even worked within the sqlite3 session I have open, very nice.
Re:Clear Your Terminal in Style by mercer on Thursday March 05, 2020 @12:08PM (#22495521)
This changes everything!
Re:Clear Your Terminal in Style by ranger207 on Thursday March 05, 2020 @02:26PM (#22497126)
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.
Re:Clear Your Terminal in Style by 3xblah on Thursday March 05, 2020 @04:16PM (#22498378)
Can substitute a forward slash for the 0 and remove the quotes

   printf \\33c
Another way is to use a program that converts hex to binary. A short script to use when there is no clear, tput, etc, e.g., xxd or nc-data

   exec echo 1b63 |exec xxd -p -r

   echo -e '27\n99\n' |exec nc-data -g

   exec echo |exec sed '1i\
   27 \
   99 

   ' |exec nc-data -g
Re:Clear Your Terminal in Style by teddyh on Thursday March 05, 2020 @05:25PM (#22499007)
\ is a backslash

/ is a forward slash, a.k.a. simply “slash”

Re:Clear Your Terminal in Style by 3xblah on Thursday March 05, 2020 @06:56PM (#22499740)
Not sure why I always get this wrong. Maybe it is because when I draw these characters on a surface, I start from the top not the bottom. Hence the line goes forward for a "backslash" and backward for a "forward slash". What is the etymology of these terms?

Probably better to just use "escape" for backslash and "slash" for forward slash.

Re:Clear Your Terminal in Style by JdeBP on Friday March 06, 2020 @10:28AM (#22504278)
As I said elsewhere in this discussion, use DECSTR instead of RIS unless you really need all of the things that RIS does to actual terminals, like performing selftests and resetting the serial connection. Habitual use of RIS is a bad habit to get into.
Re:Clear Your Terminal in Style by samatman on Thursday March 05, 2020 @03:22PM (#22497735)
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...

Re:Clear Your Terminal in Style by plq on Thursday March 05, 2020 @01:14PM (#22496306)
KDE's Konsole has it at CTRL+ALT+K by default.

The command "tput clear" should work everywhere though. And frankly, while obviously more work than a keyboard shortcut, it's not that much of an effort.

Re:Clear Your Terminal in Style by mzs on Thursday March 05, 2020 @04:29PM (#22498527)
Use clear and the flush_scrollback escape:

  $ clear; printf '\e[3J'
(edit: whoops wrong URL, sorry https://apple.stackexchange.com/a/113168 )

https://unix.stackexchange.com/a/530146

Re:Clear Your Terminal in Style by m463 on Thursday March 05, 2020 @06:40PM (#22499638)
I use this too but on linux, I am constantly hitting cmd-k and control-l in a sort of futile attempt to reset the screen correctly.

I think this needs a solution -- a keymapping and a function that resets the terminal need to be consciously united.

actually, I think I need a full set of keystrokes for linux. Somehow on ubuntu pressing the command key leads to all the windows rearranging like expose on mac.

sigh.

Re:Clear Your Terminal in Style by kdeldycke on Thursday March 05, 2020 @10:52AM (#22494565)
You can make your life easier on macOS by aliasing the `⌘-K` shortcut, as in: https://github.com/kdeldycke/dotfiles/blob/23ac0cd2a6c944242...
Re:Clear Your Terminal in Style by jchook on Thursday March 05, 2020 @06:43PM (#22499664)
When I switched from macOS to Linux, not having ⌘-K really bugged me.

However I found out that most terminal emus on Linux also have this feature as Ctrl-L.

In gnome-terminal you have to press Ctrl-K to clear the screen, and then Ctrl-L to redraw the prompt.

The bash manual documents Ctrl-L as "Clear the screen leaving the current line at the top of the screen."

Re:Clear Your Terminal in Style by SonicSoul on Thursday March 05, 2020 @12:21PM (#22495668)
Is it possible to bring it back? I’ve pressed it accidentally on server window and lost the whole svr output ( I know I could look at logs but it would still be nice to quickly bring back stdout)
Re:Clear Your Terminal in Style by Tyr42 on Thursday March 05, 2020 @09:06AM (#22493561)
Whoa, someone downstream says `reset` clears scrollback.
Re:Clear Your Terminal in Style by blattimwind on Thursday March 05, 2020 @10:22AM (#22494230)
Konsole has that since forever.
Re:Clear Your Terminal in Style by texorcist on Thursday March 05, 2020 @12:07PM (#22495516)
You don't know ctrl+L?
Re:Clear Your Terminal in Style by notatoad on Thursday March 05, 2020 @02:33PM (#22497199)
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 by jchook on Thursday March 05, 2020 @06:38PM (#22499610)
Alacritty clears with Ctrl-L, out-of-the-box.

Also, from `man bash`...

> clear-screen (C-l) Clear the screen leaving the current line at the top of the screen. With an argument, refresh the current line without clearing the screen.

Re:Clear Your Terminal in Style by microcolonel on Thursday March 05, 2020 @10:07AM (#22494070)
Also, Terminal.app seems to implement almost as many extensions as XTerm, and does them pretty well.

It's too bad it's so slow though (in terms of throughput, that is; latency is pretty okay).