Live data from Hacker News

Mastering Bash and Terminal

blockloop.io

111–120 of 186 posts

Re: Mastering Bash and Terminal

#111
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…

That these, probably the most useful Readline functions by far, are not bound to any keys by default is crazy. To me it makes more sense to bind them to M-p and M-n though.

Re: Mastering Bash and Terminal

#112
Another trick is to use "!!" which is the last command launched, especially useful if you forgot a "sudo" in front of your command, just write

  sudo !!
In the same way, "!*" is all the arguments of your previous command, and "!$" only the last one.

Re: Mastering Bash and Terminal

#113
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…

Also, when you use a lot of scripts that only work with bash (there are more than you'd expect, despite zsh saying it is bash compatible) then you have the choice of either rewriting these scripts or using bash. Most ppl will choose not to rewrite.

Re: Mastering Bash and Terminal

#114
post #90

The one tool that saved me quite possibly a few months of typing paths over my lifetime is autojump: https://github.com/wting/autojump . I can't imaging a terminal workflow without it.

This should be shouted out regulary to anyone using any type of command line until everybody uses it. I cringe everytime I see someone spelling out cd /mega/long/path/to/a/place/i/visit/multiple/times/every/single/day. Ok some of them already know about tab completion, but it just hurts to see that knowing all that's really needed is j d or z d or so.

Re: Mastering Bash and Terminal

#115
post #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.

With tpope's fugitive.vim this is just :Gstatus and :Gcommit

Re: Mastering Bash and Terminal

#116
post #27

Earlier quoted context omitted.

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

[deleted]

Re: Mastering Bash and Terminal

#117
> "tool that every developer uses regardless of language, platform, or framework it's the terminal"

I'm not sure I agree with that. If you work in a decent IDE and your vcs is not git then you can do pretty well without a terminal. Especially on Windows.

Post reply on HN