Live data from Hacker News

Mastering Bash and Terminal

blockloop.io

31–40 of 186 posts

Re: Mastering Bash and Terminal

#31
post #25
post #14

The article is nice but a small part of it rubs me the wrong way: > I know there are some cool newcomers out there like zsh and fish, but after trying others out I always found that some of my utilities were missing or ill-replaced. First of all bash was first released in 1989 and zsh arrived just 1 year later so zsh is in no way a newcomer. Secondly zsh is almost strictly a bash superset so I don't know what he was…

On my version of zsh I was not able to do the following which is available on bash: http://unix.stackexchange.com/a/203075

Well, from what I see here: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#..., there's no predefined function for Emacs mode (I could only find the vi mode one: vi-find-next-char).

On the other hand, if you look at the whole widgets section, I'm pretty sure you could hack it yourself since zsh supports used defined widgets (widgets are basically functions used by the zsh command editor).

I never said that it's easy, just that zsh is basically a bash superset. However that does mean that in some occasions this means that you want a Prius and instead get a Ford Mustang kit that you have to assemble yourself :D

Re: Mastering Bash and Terminal

#32
post #19

Regarding macOS and bash, it is slightly remiss of the article to not at least mention that the version of bash in macOS is 1. Ancient. 2. Will most likely never be updated by Apple (Most GNU- and Linux-based systems, and also Windows, on the other hand, continue to use the latest versions.)

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

GPLv3.

Re: Mastering Bash and Terminal

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

The default key bindings in bash are listed in the readline section of the bash man page (they mostly match the emacs key bindings).

Re: Mastering Bash and Terminal

#34
post #29

Personally, I found the following to be extremely easy and powerful. A no-brainer that should be a bash default really. if [ -t 1 ] then # search for commands that start off with the same characters already typed bind '"\e[A":history-search-backward' bind '"\e[B":history-search-forward' fi One of my friends also recommended version-controlling your config files and storing them on gitlab, which I'm only sad I didn't…

You can also put those in your ~/.inputrc

Re: Mastering Bash and Terminal

#36
On macOS, instead of

    ip addr show en0 | grep -inet\ | awk '{ print $3 }' | awk -F/ '{print $1}' | pbcopy
you can use:

    ipconfig getifaddr en0
If you wanna stick with ip addr, a more compact command is:

    ip addr show en0 | awk '/inet/{split($2,a,"/"); print a[1]}'

Re: Mastering Bash and Terminal

#38
post #27

Earlier quoted context omitted.

I didn't know about :r in combination with !. That's neat. I typically use :r for reading a file into the current buffer (instead of cp ). Thanks for sharing. I don't find myself using ! commands when I know there are multiple commands that I need to run (like your last example). That's usually when I'll suspend and then use the command line. Could you elaborate on "wreak havoc on your vim session?" I wasn't aware th…

> I didn't know about :r in combination with ! You can even use :w in combination with !. For example :w !xclip to write the vim buffer contents to the clipboard. You could visually highlight part of the buffer and do the same thing for just the text you want.

This is also useful for iterating on a throw-away script - something too long to type on one line in the shell, but not significant enough to be worth saving to a file. Put it together in an unnamed buffer, and ":w !" it to the relevant interpreter (eg ":w !perl") whenever you want to run it.

Re: Mastering Bash and Terminal

#39

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…

My personal favourite trick with ":r!" is, in a new buffer, running :0r! grep -rn $pattern $path_to_directory or any other command that outputs lines containing "$path_to_file:$line_no" (eg most linters). With that output read into a buffer, placing the cursor anywhere in the "path:line" part and hitting ^wF will open that file in a new split window, and jump the cursor straight to the indicated line - or you can do…

I know that vim has the built in :grep command that does what you describe. The results are listed in the preview window and pressing enter will open the corresponding file and place the cursor at the desired line.

Re: Mastering Bash and Terminal

#40
post #19

Regarding macOS and bash, it is slightly remiss of the article to not at least mention that the version of bash in macOS is 1. Ancient. 2. Will most likely never be updated by Apple (Most GNU- and Linux-based systems, and also Windows, on the other hand, continue to use the latest versions.)

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 people for actually using the GPL-licensed software you ship. The second is that it carefully prevents TiVoization, locking down hardware so that people can’t actually run the software they want.

So, which of those things are they planning for OS X, eh?

I’m also intrigued to see how far they are prepared to go with this. They already annoyed and inconvenienced a lot of people with the Samba and GCC removal. Having wooed so many developers to the Mac in the last decade, are they really prepared to throw away all that goodwill by shipping obsolete tools and making it a pain in the ass to upgrade them?

Post reply on HN