Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

71–80 of 288 posts

Re: Ask HN: Best things in your bash_profile/aliases?

#71
I dislike pretty much the entire Windows command line, except for one small bit of it: `start` (for the purpose of launching stuff in the background and disowning it, not for the `xdg-open`-like functionality).

So, I had this in my rc files for a while:

  start() { nohup "$@" &> /dev/null &; }
After that, I replaced the function with the custom command from here: http://web.archive.org/web/20151221072546/https://felixmilea...

I'd still like to have auto completion for this, though, but I never got around to learning about the ways to achieve that in bash and zsh.

Edit: Also, the one I probably use the most:

  alias l="ls -ltrash"
although I've started to replace it with

  e() { exa -bghHliSa --color=always "$@" | bat; }
  et() { exa -bghHliSTa --color=always "$@" | bat; }

Re: Ask HN: Best things in your bash_profile/aliases?

#73
I've used these so much:

    function gc() { grep -rnI "$@" * ;}
    function gcA() { grep -rnI -A 5 "$@" * ;}
    function gcB() { grep -rnI -B 5 "$@" * ;}
    function gcC() { grep -rnI -C 5 "$@" * ;}
    function gcf() { grep -rnIl "$@" * ;}
Just helper functions built on top of grep

Re: Ask HN: Best things in your bash_profile/aliases?

#74

I've used these so much: function gc() { grep -rnI "$@" * ;} function gcA() { grep -rnI -A 5 "$@" * ;} function gcB() { grep -rnI -B 5 "$@" * ;} function gcC() { grep -rnI -C 5 "$@" * ;} function gcf() { grep -rnIl "$@" * ;} Just helper functions built on top of grep

And what do they do? It's not obvious.

edit: Thank you both!

Re: Ask HN: Best things in your bash_profile/aliases?

#75

Earlier quoted context omitted.

You might be looking for this: https://github.com/nvbn/thefuck/blob/master/README.md

Thanks, but my computer's too old to read that page. It's a thing already?

Yes, it's a command you can use when the previous one failed for some reason, that tries to correct the typos if any, or adds sudo or a missing option...

Re: Ask HN: Best things in your bash_profile/aliases?

#77
I use bash, but I like the zsh feature where you could type "cd -n" and go back n entires in your "directory stack", so I made my own version as a function. It's probably subtly broken in some way, since it's bash, but it works relatively well for me:

  cd() {
  	# Set the current directory to the 0th history item
  	cd_history[0]=$PWD
  	if [[ $1 == -h ]]; then
  		for i in ${!cd_history[@]}; do
  			echo $i: "${cd_history[$i]}"
  		done
  		return
  	elif [[ $1 =~ ^-[0-9]+ ]]; then
  		builtin cd "${cd_history[${1//-}]}" || # Remove the argument's dash
  		return 
  	else
  		builtin cd "$@" || return # Bail if cd fails
  	fi
	# cd_history = ["", $OLDPWD, cd_history[1:]]
  	cd_history=("" "$OLDPWD" "${cd_history[@]:1:${#cd_history[@]}}")
  }
Other than that, I doubt there's much that would be generally useful to anyone.

Re: Ask HN: Best things in your bash_profile/aliases?

#79
post #56

Earlier quoted context omitted.

alias ..="cd .." If you use zsh, typing a directory name changes to it automatically. It’s almost always a very delightful thing.

Bash has this as well set autocd

that would be rather

    shopt -s autocd

Re: Ask HN: Best things in your bash_profile/aliases?

#80
Can I add something from .vimrc?

If you put the commands:

  set undofile
  set undodir=~/.vim/undodir
You get infinite undo in your files.

Now when you go into a file, delete or add some text and close your terminal down, the next time you enter vim you can (re|un)do previous operations.

Has saved my ass more times than I care to mention over my career!

Post reply on HN