> [ $[$RANDOM % 10] = 0 ] && do_this || do_that > This gives roughly a 1 in 10 chance of do_this running, and a 9 in 10 chance of do_that running. `do_that` having a 9 in 10 chance depends on `do_this` having a 0 chance of returning a falsy status.
Clear Your Terminal in Style
71–80 of 133 posts
Re: Clear Your Terminal in Style
#72I’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.
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
#73Earlier quoted context omitted.
Is ctrl+c handled; by the terminal emulator? ctrl+l allows to clear when the prompt is non-empty, maybe parent poster meant that
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.
Re: Clear Your Terminal in Style
#74I’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…
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
#75Re: Clear Your Terminal in Style
#76Earlier quoted context omitted.
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…
> 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
#77I’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
#78> [ $[$RANDOM % 10] = 0 ] && do_this || do_that > This gives roughly a 1 in 10 chance of do_this running, and a 9 in 10 chance of do_that running. `do_that` having a 9 in 10 chance depends on `do_this` having a 0 chance of returning a falsy status.
Afaik this is common syntax for if/else based only on the the initial condition; I can't remember where it's documented but I think it requires the do_this part to be a single expression. However, bash pitfalls recommends against using && and || except for very basic logic.
You're right that it's common, but you're wrong saying that it's based only on the initial condition:
$ true && cat nonexistent.txt || echo "shouldn't have run"
cat: nonexistent.txt: No such file or directory
should't have run
> I can't remember where it's documented but I think it requires the do_this part to be a single expressionIt's not documented like you said because it's a hack. &&/|| aren't meant to simulate if/else. These aren't expressions either. And they aren't really limited either:
$ true && { echo "true condition ran"; cat nonexistent.txt; } || echo "false condition ran"
true condition ran
cat: nonexistent.txt: No such file or directory
false condition ran
> However, bash pitfalls recommends against using && and || except for very basic logic.The fact that people end up thinking that it's an ok substitute for if/else syntax is the reason why it's recommended against.
Re: Clear Your Terminal in Style
#79Earlier quoted context omitted.
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.
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 c…
Re: Clear Your Terminal in Style
#80I've just used alias c=clear in my .bashrc and never looked back. Not even Ctrl+L feels as convenient as c+Enter
I have mapped capslock to ctrl (esc if used without modifiers) which made ctrl+L extremely comfortable for me.