Live data from Hacker News

Mastering Bash and Terminal

blockloop.io

51–60 of 186 posts

Re: Mastering Bash and Terminal

#51

Rather than temporarily suspend vim to use the terminal you can get vim to suspend and resume itself with the exclamation mark command. This has the benefit of not wreaking havoc on your vim session and allowing you to read data into vim by prefixing with r. For example :!ls will execute ls and show you the result (press enter to return) :r!ls will read the result of ls in for you More usefully :r!sed -n5,10p that/ot…

You can also use :sh which just starts a new subshell in the terminal and puts you back in vim when you exit it.

Re: Mastering Bash and Terminal

#52
post #40

Earlier quoted context omitted.

Why are you saying that Apple will not update bash? Wouldn't that be in the best interest of its users?

It would indeed be in the best interest of its users, but Apple has apparently decided that it would not be in its own best interest: http://meta.ath0.com/2012/02/05/apples-great-gpl-purge/ […] Anyway, the message is pretty obvious: Apple won’t ship anything that’s licensed under GPL v3 on OS X. Now, why is that? There are two big changes in GPL v3. The first is that it explicitly prohibits patent lawsuits against pe…

Or, it could just switch the default shell to Z shell. First thing I do on a new Mac, is chsh -> zsh. Ships with an up to date (enough) version of that.

Re: Mastering Bash and Terminal

#53
post #11

> 8. alt-w - delete the word behind of the cursor He means “ctrl-w”. But since that only works in bash, not in Emacs or other tools with Emacs key bindings, it makes more sense to use (in his terminology) “alt-backspace”. This does the same thing, and works both in the shell and in Emacs-like environments.

Another advantage to using alt-backspace over ctrl-w is that the former has the same semantics as alt-b. ctrl-w considers a word to be anything surrounded by spaces, whereas alt-b and alt-backspace consider a word to be any consecutive string of word characters.

Re: Mastering Bash and Terminal

#55
Worth it just for finding out about `stty -ixon`. I never would have guessed from the `stty` man page description that this option would give me back C-s and C-q to bind to something actually useful.

Re: Mastering Bash and Terminal

#56
I actually resolved most of that common issues with just bash: :)

Substring history search, so you can use just a substring to look for a argument,command. Binded to ctr+r/s by default. ;)

https://github.com/liloman/asyncBash#use

Changing directories: Last n directories, transparent popd/pushd.

https://github.com/liloman/dirStack

Movements: vim-surround for your cli, so you can do ysiw" o whatever... ;)

https://github.com/liloman/bash-surround

Control-n right: So just type the start and control+n to search for the arguments/commands starting with whatever. And the classical up/down to look up for a complete history line:

https://github.com/liloman/dotfiles/blob/master/bash/.inputr...

https://github.com/liloman/dotfiles/blob/master/bash/.inputr...

There're a ton of hidden functionality and customization behind the classical bash instalation. :)

Re: Mastering Bash and Terminal

#57
About bindings, it would have been better to redirect to:

LESS=+/"DEFAULT KEY BINDINGS" man readline

assuming it exists on mac.

About suspend, what's the benefit of suspending vim using C-z? Shouldn't you use a terminal multiplexer instead, or even terminal tabs if you don't want to learn how to use tmux or screen (which I find weird if you already spent time to learn how to use vim but alright)?

I only ever suspend a program when I want it to stop, for instance because it slows other programs and I realize I would rather resume it when I'm not in front of my computer. Even in that case, I often just renice the program instead. Stopping a program just because you want to run some bash commands looks like an anti-pattern to me, but maybe there are better motives I'm not aware of.

Re: Mastering Bash and Terminal

#58

I'm curious about the popularity of Bash vis a vis, say, Csh. Is Bash more popular due to superior features, or is simply because it is the default on quite a few *nix distros (and macOS)?

I used to use zsh way back in the day because it was clearly superior to bash, then decades ago switched to bash because it was everywhere by default and my job involved using lots of computers that only had bash on them, then about 4 or 5 years ago I switched back to zsh because I realized that it really didn't matter that I used zsh on my own machine and bash on others, and zsh was still better than bash.

These days bash seems to have a lot closer feature parity to zsh, and I'd be curious to read an up-to-date comparison of both shells to determine if either is clearly better than the other.

Re: Mastering Bash and Terminal

#59
bash (and shells in general) are so hacky (in a bad way) that I wouldn't want to waste my time mastering them. Whenever a shell script grows beyond 10 or 20 lines, I try to rewrite it in a "real" programming language. Fancy shell tricks are a code smell to me, and clarity and simplicity are of far greater importance.

For me, as far as shells go it's usually enough to know the basics and be able to look stuff up when debugging other people's shell scripts.

Re: Mastering Bash and Terminal

#60
post #57

About bindings, it would have been better to redirect to: LESS=+/"DEFAULT KEY BINDINGS" man readline assuming it exists on mac. About suspend, what's the benefit of suspending vim using C-z? Shouldn't you use a terminal multiplexer instead, or even terminal tabs if you don't want to learn how to use tmux or screen (which I find weird if you already spent time to learn how to use vim but alright)? I only ever suspend…

I use tmux. The benefit of using suspend is not having to move around multiple windows/tabs. I try to keep those to a minimum (usually one or two). With suspend I can stick with the same tmux window for editing and cli within the same context. It's a personal preference over managing multiple windows.
Post reply on HN