Live data from Hacker News

Ask HN: Best things in your bash_profile/aliases?

news.ycombinator.com

191–200 of 288 posts

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

#192

This one I use daily without thinking about it - it shares my bash history between screens and sessions on a given machine and extends it (grabbed from some corner of the internet): # shares history between tabs with prompt_command HISTSIZE=9000 HISTFILESIZE=$HISTSIZE HISTCONTROL=ignorespace:ignoredups _bash_history_sync() { builtin history -a #1 appends command to histfile HISTFILESIZE=$HISTSIZE #2 sets max size bui…

> this gets the git branch to display when I cd into a git repo

It's early and I'm lazy... will this always parse the branch upon entering any git directory?

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

#193
post #192

This one I use daily without thinking about it - it shares my bash history between screens and sessions on a given machine and extends it (grabbed from some corner of the internet): # shares history between tabs with prompt_command HISTSIZE=9000 HISTFILESIZE=$HISTSIZE HISTCONTROL=ignorespace:ignoredups _bash_history_sync() { builtin history -a #1 appends command to histfile HISTFILESIZE=$HISTSIZE #2 sets max size bui…

> this gets the git branch to display when I cd into a git repo It's early and I'm lazy... will this always parse the branch upon entering any git directory?

Edit: ugh, nevermind it _is_ early. I know that answer. Thanks for the cool functions.

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

#194
post #140

One thing I do is to put this snippet in .bashrc or .profile for i in ${HOME}/.bash.d/*.sh do if [ -r ${i} ] ; then . ${i} fi done And drop some custom scripts in ${HOME}/.bash.d/ like alias.sh, env.sh (my common .bash.d scripts are saved in a git repository)

Whoa, I know someone who does exactly this. Is this a common pattern? Unless you're him!

.d is a common Unix include directory pattern. See cron.d, xinetrc.d, conf.d etc. Packages can just add/remove things to the include dir rather than modifying the main config.

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

#197
My favorite new one that I have been using a lot:

  function cheat() {
      curl cht.sh/$1
  }
It queries the cht.sh cheatsheet of various Unix commands. 'cheat tar' prints:

  # To extract an uncompressed archive:
  tar -xvf /path/to/foo.tar
  
  # To create an uncompressed archive:
  tar -cvf /path/to/foo.tar /path/to/foo/
  
  # To extract a .gz archive:
  tar -xzvf /path/to/foo.tgz
  
  # To create a .gz archive:
  tar -czvf /path/to/foo.tgz /path/to/foo/
  
  # To list the content of an .gz archive:
  tar -ztvf /path/to/foo.tgz
  
  # To extract a .bz2 archive:
  tar -xjvf /path/to/foo.tgz
  
  # To create a .bz2 archive:
  tar -cjvf /path/to/foo.tgz /path/to/foo/
  
  # To extract a .tar in specified Directory:
  tar -xvf /path/to/foo.tar -C /path/to/destination/
  
  # To list the content of an .bz2 archive:
  tar -jtvf /path/to/foo.tgz
  
  # To create a .gz archive and exclude all jpg,gif,... from the tgz
  tar czvf /path/to/foo.tgz --exclude=\*.{jpg,gif,png,wmv,flv,tar.gz,zip} /path/to/foo/
  
  # To use parallel (multi-threaded) implementation of compression algorithms:
  tar -z ... -> tar -Ipigz ...
  tar -j ... -> tar -Ipbzip2 ...
  tar -J ... -> tar -Ipixz ...
You do have to be online, but there are ways of downloading the directory of cheat sheets to use offline as well.

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

#198

  unameOut="$(uname -a)"

  case "${unameOut}" in

	*Microsoft*) machine="WSL";;

	Linux*)      machine=Linux;;

	Darwin*)     machine=Mac;;

	CYGWIN*)     machine=Cygwin;;

	MINGW*)      machine=MinGw;;

	*)           machine="UNKNOWN:${unameOut}"

  esac

  unset unameOut

  PROMPT_COMMAND='echo -ne "\033]0;[${machine}] ${USER}@${HOSTNAME}: ${PWD}\007"'

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

#199
post #182

I use 'u' to navigate up parent directories: alias u="cd .." alias uu="cd ../.." alias uuu="cd ../../.." alias uuuu="cd ../../../.."

Interesting. I have the same, but aliases to `.` instead.

  alias ..='cd ../'
  alias ...='cd ../../'
  alias ....='cd ../../../'
  alias .....='cd ../../../../'

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

#200
post #193
post #192

Earlier quoted context omitted.

> this gets the git branch to display when I cd into a git repo It's early and I'm lazy... will this always parse the branch upon entering any git directory?

Edit: ugh, nevermind it _is_ early. I know that answer. Thanks for the cool functions.

Hope you find them as useful as I have!
Post reply on HN