Skip to content

Instantly share code, notes, and snippets.

@kristiewirth
Last active December 5, 2022 18:27
Show Gist options
  • Save kristiewirth/c9b7e7aa1331f9a7a44fabc4d4065d3f to your computer and use it in GitHub Desktop.
Save kristiewirth/c9b7e7aa1331f9a7a44fabc4d4065d3f to your computer and use it in GitHub Desktop.
A template for a bash_profile with helpful additions
# Navigating quickly to commonly used directories (change to your own)
export CDPATH=.:~:/Users/kristiewirth/Documents:/Users/kristiewirth/Documents/work
# Changing command line beginning to just be directory and $
export PS1="\W/ $ "
# Expanding bash completion
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
elif [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then
. /opt/local/etc/profile.d/bash_completion.sh
fi
# Allowing for slight misspellings when using cd
shopt -s cdspell
# Setting VSCode as default editor
export EDITOR="code -w"
# Show Git branch in prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
# Pyenv
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
# Poetry
export PATH="$HOME/.poetry/bin:$PATH"
# IPython (force using virtual environment when activated)
alias ipython='python -m IPython'
alias ipy="python -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"
# Setting jupyter notebook option to launch without data limits
alias jupylarge="python -m notebook --NotebookApp.iopub_data_rate_limit=10000000000"
# Add tab completion for many Homebrew commands
if type brew &>/dev/null
then
HOMEBREW_PREFIX="$(brew --prefix)"
if [[ -r "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]
then
source "${HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
else
for COMPLETION in "${HOMEBREW_PREFIX}/etc/bash_completion.d/"*
do
[[ -r "${COMPLETION}" ]] && source "${COMPLETION}"
done
fi
fi
# Bash completion for checking out Git branches
alias gitc="git checkout"
_git_checkout_branch_complete() {
local cur prev opts
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
opts=$(git branch | cut -c 3-)
COMPREPLY=( $(compgen -W "$opts" -- $cur) )
}
complete -o nospace -F _git_checkout_branch_complete "gc"
# Git commands
alias grh="git reset --hard HEAD~1"
alias grs="git reset --soft HEAD~1 && git reset"
alias gfa="git fetch --all"
alias gnb="git checkout -b"
alias gca="git add -A; git commit -m"
alias gdabl="git branch | grep -v \"origin$\" | grep -v \"master$\" | grep -v \"develop$\" | grep -v \"main$\" | grep -v HEAD | xargs git branch -D"
alias gdabr="git branch -r | grep \"origin$\" | grep -v \"master$\" | grep -v \"develop$\" | grep -v \"main$\" | grep -v HEAD | cut -d/ -f2- | while read line; do git push origin :heads/$line; done;"
gcr() { git checkout -b "$@" origin/"$@"; }
# Poetry commands
alias poetn="poetry install"
alias poeta="source .venv/bin/activate"
# Installing packages commands
alias pips="pip install --upgrade pip; pip install ipython; pip install pylint; pip install notebook; pip install black"
alias pipr="pip install -r requirements.txt"
alias spacyn="poetry add spacy && python -m spacy download en_core_web_sm"
# Misc commands
alias ll='ls -alh' # List file
alias lls='ls -alhS' # List files by size
alias llsr='ls -alhSr' # List files by size (reverse)
alias lld='ls -alht' # List files by date
alias lldr='ls -alhtr' # List files by date (reverse)
alias lldc='ls -alhtU' # List files by date created
alias lldcr='ls -alhtUr' # List files by date created (reverse)
alias ..='cd ..'
alias ...='cd ../../../'
alias ....='cd ../../../../'
alias .....='cd ../../../../'
alias sb="source ~/.bash_profile"
alias pipreqsp="pipreqs . --print"
alias kerneld="jupyter kernelspec uninstall"
kernela() { ipython kernel install --name "$@" --user; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment