Live data from Hacker News

Mastering Bash and Terminal

blockloop.io

121–130 of 186 posts

Re: Mastering Bash and Terminal

#121
post #82

In the spirit of sharing: one of my favorite lines in my bashrc is the alias of `rm` to `rm -i`. This prompts for a confirmation. You might not need it but I deleted some important, not-yet-checked-in-git files in the past by accident. If you want to delete everything and don't want to keep typing yes just do `yes | rm bla`.

No need to do that: just pass -f. The last flag "wins": $ rm -fi blah remove blah? $ rm -if blah $ # confirmation suppressed

With GNU rm, you can put the -f at the end, which I do for safety.

  rm -i x y z -f

Re: Mastering Bash and Terminal

#122

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 more often

    :make
nowadays rather than

    :!make

Re: Mastering Bash and Terminal

#123

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…

With the likes of

    :cfile
    :cbuffer
one can turn that file/buffer directly into a quickfix list, where simply enter will take one to the relevant position. Messages with column positions are recognized in quickfix lists (:help errorformat).

Re: Mastering Bash and Terminal

#124
post #41

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…

> That's usually when I'll suspend and then use the command line. That's when I run !bash, enter my list of commands, then exit.

If one wants something that isn't limited to one shell, and invokes the interactive shell that the user has chosen, there is of course

    :shell

Re: Mastering Bash and Terminal

#125
Those Emacs commands you mention for moving around on the line also work in a lot of other text fields, in a lot of other programs.

Notably they don't work in MS Office, but they work in web browsers and practically every other app I have on my Mac.

Re: Mastering Bash and Terminal

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

Having a .dotfiles/ repo makes life so much easier. Seriously.

Re: Mastering Bash and Terminal

#127
post #20

Earlier quoted context omitted.

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…

The problem with installing zch on my desktop is that I won't have it on the servers I SSH into. I need to know the proper spells and incantations that will work on a wide variety of distros and versions, many of which I don't personally maintain. Therefore, bash.

Indeed. The same argument applies to other exotic tooling, interesting vim plugins with many dependencies, etc.

It's one reason to keep one's environment relatively standard and boring. Otherwise, one comes to be dependent -- psychologically, at least -- on one's meticulously configured custom environment, and either chafes at its absence elsewhere or spends a great deal of time copying it everywhere.

Re: Mastering Bash and Terminal

#128

I've tried bash, zsh, and fish. After trying all three, I'm staying with fish. bash and zsh don't have sensible defaults, and configuring them is tedious. fish works great out of the box, and it's really fast. When I picked up zsh I used oh-my-zsh and later prezto, but it was slow and figuring out what everything all the framework did was complicated. With fish I have a setup.fish script that defines all my universal…

I use fish too but I'm thinking about switching back to zsh. Mostly due to incompatible software here and there (like nvm) and lack of completions for a lot of cli tools.

Re: Mastering Bash and Terminal

#129
post #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://githu…

That is amazing, thanks for sharing. I'm gonna steal some ideas from asyncBash

I'm glad you liked it. :)

I don't understand why the default bash/readline doesn't get something related for substring search or way better autocompletions, it's really not that hard definitely (actually quite easy) and even when that's the reason for a lot of people to choose zsh over bash.

Post reply on HN