albertyw/dotfiles

View on GitHub
files/bashrc

Summary

Maintainability
Test Coverage
#!/bin/bash

### Setting variables
export EDITOR="nvim"
export LC_ALL="en_US.UTF-8"
export LANGUAGE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export TERM="xterm-256color"
export HISTCONTROL="ignorespace"
export CLICOLOR="1"
export LSCOLORS="gxBxhxDxfxhxhxhxhxcxcx"

# Set bash prompt
blue='\[\e[1;34m\]'
red='\[\e[1;31m\]'
yellow='\[\e[1;33m\]'
magentabackground='\[\e[1;45m\]'
reset='\[\e[0m\]'
if [[ "$(hostname)" == *"personal"* ]] || [[ "$(uname)" == "Darwin" ]] || [[ "$(hostname)" == *"desktop"* ]]; then
    PS1="${blue}\u${red}@${yellow}\h${red} \w \$ ${reset}"
else
    PS1="${blue}\u${red}@${yellow}${magentabackground}\h${reset}${red} \w \$ ${reset}"
fi

### Assorted aliases
function path() { echo "$PATH" | tr ':' '\n'; }
alias grep='grep --color=auto'
oports() { echo 'User:      Command:   Port:'; echo '----------------------------' ; lsof -i 4 -P -n | grep -i 'listen' | awk '{print $3, $1, $9}' | sed 's/ [a-z0-9\.\*]*:/ /' | sort -k 3 -n |xargs printf '%-10s %-10s %-10s\n' | uniq; }
alias mem="printf '\033[?7l' && ps aux | sed -n 1p && ps aux | tail -n +2 | sort -brnk 4 | head -n 20 && printf '\033[?7h'"
alias cpu="printf '\033[?7l' && ps aux | sed -n 1p && ps aux | tail -n +2 | sort -brnk 3 | head -n 20 && printf '\033[?7h'"
alias sudo='sudo '
alias fucking='sudo'
alias scp="rsync"
alias rsync='rsync -vazhP'
alias alert='echo -e "\a"'
alias diff='icdiff'
alias tree='tree -C'
alias du='du -h'
alias mkdir='mkdir -p'
alias myip='myipv4'
alias myipv4='curl --silent http://ip4only.me/api/ | cut -d',' -f2'
alias myipv6='curl --silent http://ip6only.me/api/ | cut -d',' -f2'
function geoip { curl "https://ipinfo.io/$1"; }
export -f geoip
if [[ $(uname) == Linux ]]; then
    alias ls='ls --color=always'
fi
alias serve="python3 -m http.server"
alias gosymlink='cd "$(realpath "$(pwd)")"'
alias portgrep="sudo ngrep -d any port"
alias apt-get="apt"
alias req-update="~/.dotfiles/scripts/git/req-update/req_update/req_update.py"
if [[ $(uname) == Linux ]]; then
    alias portlist="sudo netstat -lntup"
elif [[ $(uname) == Darwin ]]; then
    alias portlist="sudo lsof -i -P | grep -i 'listen'"
    if [ -f /usr/local/bin/vim ]; then
        alias vi=/usr/local/bin/vim
    fi
fi
if command -v nvim > /dev/null; then
    alias vi=nvim
fi

### Adjusting the PATH
export PATH="$PATH:$HOME/.dotfiles/bin"

# Python
# 1-May-2020: Fix for Keyring error with pip. Hopefully new pip will fix it
# soon https://github.com/pypa/pip/issues/7883
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
if [[ $(uname) == Darwin ]]; then
    # Read brew python, needed for virtualenvwrapper
    export PATH="/usr/local/opt/python/libexec/bin:$PATH" 
fi
if [ -s "/usr/local/bin/virtualenvwrapper_lazy.sh" ]; then
    python3location="$(command which python3)"
    export VIRTUALENVWRAPPER_PYTHON=$python3location
    [ -s "/usr/local/bin/virtualenvwrapper_lazy.sh" ] && . /usr/local/bin/virtualenvwrapper_lazy.sh
fi
source "$HOME/.dotfiles/files/completion/django-completion.sh"

# Go
export GOPATH=$HOME/gocode
export PATH="$PATH:/usr/local/go/bin"
export PATH="$PATH:$GOPATH/bin"

# Node
export PATH="$PATH:node_modules/.bin"
export NODE_OPTIONS=--max_old_space_size=4096
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
if command -v npm > /dev/null; then source <(npm completion); fi
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
source "$HOME/.dotfiles/files/completion/npx-completion.sh"

# Ruby
export PATH="$PATH:$HOME/.rvm/bin"                    # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
if command -v rbenv > /dev/null; then eval "$(rbenv init -)"; fi
alias rspec='xvfb-run -a bundle exec rspec'

# CUDA
if [ -d "/usr/local/cuda-11.2/bin/" ]; then
    export PATH=/usr/local/cuda-11.2/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
fi

# Direnv
if command -v direnv > /dev/null; then
    eval "$(direnv hook bash)"
    show_virtual_env() {
      if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
        echo "($(basename "$VIRTUAL_ENV")) "
      fi
    }
    export -f show_virtual_env
    PS1='$(show_virtual_env)'$PS1
fi

[[ -r $HOME/.bashrc_local ]] && . ~/.bashrc_local

### Git updates
~/.ssh/chmod.sh
~/.dotfiles/scripts/sync-dotfiles.sh &
disown

# Uber-specific stuff
[ -r /Users/albertyw/.profile_lda ] && . /Users/albertyw/.profile_lda