Live data from Hacker News

Mastering Bash and Terminal

blockloop.io

21–30 of 186 posts

Re: Mastering Bash and Terminal

#21
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.)

I don't use the version that ships with MacOS. You can install the latest version with `brew install bash`. I'm currently using 4.4.5.

Nevertheless, I updated the post to add bash 4 to the assumptions.

Re: Mastering Bash and Terminal

#22
post #20

Earlier quoted context omitted.

I wasn't so much commenting on the release date when I said "newcomers." Mostly commenting on my personal experience. I've been using bash for a long time and only recently have I seen zsh get so popular. It's entirely possible that only the people I know have only recently taken an interest in it. I would have to run zsh again to remember the pieces that I didn't like. I might have been able to configure my way arou…

zsh was quite popular when I first went spelunking in *NIX-land (2005). oh-my-zsh, which was a decent boost to zsh popularity, seems to have been around since 2009 ( http://ohmyz.sh/ ). zsh has always been held back by the "default browser"-syndrome: Linux and Mac OS both come with "good enough" default shells, so few people actually want to go through the effort of switching. Especially since there is a bit of a lea…

You're probably right about oh-my-zsh. I really only hear people refer to zsh as "oh my zsh" which makes me smile.

Re: Mastering Bash and Terminal

#23
post #17

I recommend to install mc (Midnigth Commander) and bash-completion (if bash is your shell of choice) as first terminal tools. mc allows to explore system efficiently while not standing in my way, because I can always press ctrl-O and get my shell back. bash-completion saves time on typing of commands. Other tools I install often are htop (better ps) and strace.

all of these are my go-to tools. I also edit inputrc to make pgup and pgdn history search - something I picked up from SuSE version 15 years ago, and stuck.

Re: Mastering Bash and Terminal

#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

Re: Mastering Bash and Terminal

#26

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…

Regarding the last git command you listed, I actually find it better to do

    :r !git status -v
And at the to of the result, type my formatted git commit message, visually highlight the message I just typed, and then use the following vim command

    :r !git commit -F -
Which reads the commit message from standard input.

Re: Mastering Bash and Terminal

#27

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…

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.

Re: Mastering Bash and Terminal

#28
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?

Re: Mastering Bash and Terminal

#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 do sooner. It's been such a help in keeping my aliases and configs in sync, as I make changes across numerous different machines.

Re: Mastering Bash and Terminal

#30

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 ^wgF to do the same in a new tab page.

It's a very handy way to work through a big list of work items spread across many files. You do need to coax the right format for it out of your tools, but fortunately "path:line" is pretty de-facto standard.

(Incidentally, I do ":0r" so it inserts the read-in lines at the very top of the file - just ":r" in an empty buffer leads to a leading blank line, which I find irrationally annoying.)

Post reply on HN