HomeFontsAbout

Bash configuration

Updated on 2021-11-13

I was always confused as to if I should put a specific bash setting in my .bashrc or in my .bash_profile. So I decided to just put everything in .bashrc and have my .bash_profile source it. I have been doing this for around ten years now and it seems to be working.

bash_profile

# Keep all configs in bashrc!
if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

bashrc

# Prevent sourcing bashrc multiple times.
if [ -n "$BASHRC" ]
then
    return
fi
readonly BASHRC=1

# Aliases
alias vim=nvim
alias ls="ls -F"
if which fdfind > /dev/null
then
  alias fd=fdfind
fi

# Paths
export PATH="$HOME/anaconda3/bin:$PATH"
export PATH="$(ls -d $HOME/.nvm/versions/node/* | tail -1)bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"

# History
HISTCONTROL=ignoreboth
shopt -s histappend
shopt -s checkwinsize
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'

# Prompt
git_branch() {
  git branch --no-color 2> /dev/null\
  | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \(\1\)/';
}
export PS1='\[\e[0;32m\]\w\[\e[0;31m\]$(git_branch)\[\e[0m\]
$ '

# NVM (lazy load)
nvm() {
  unset -f nvm
  export NVM_DIR="$HOME/.nvm"
  [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
  [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
  nvm "$@"
}

# bash completion
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

Copyright © 2020-2021 thestuffido.xyz All Rights Reserved