Skip to content

Instantly share code, notes, and snippets.

@susanBuck
Last active February 10, 2024 14:33
Show Gist options
  • Save susanBuck/ee3a0a53d72198c1a244 to your computer and use it in GitHub Desktop.
Save susanBuck/ee3a0a53d72198c1a244 to your computer and use it in GitHub Desktop.
.bash_profile example
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# Suppress message about using zsh
export BASH_SILENCE_DEPRECATION_WARNING=1
# ------------------------------------
# MOTD (Message of the Day)
# What you see when Terminal opens
# ------------------------------------
echo "----------------------------"
echo "Loaded ~/.bash_profile"
echo ""
echo "To edit run: configedit"
echo "To refresh run: configrefresh"
echo "All aliases: alias"
echo "----------------------------"
# ------------------------------------
# Configure prompt
# Includes special handling for git repos
# ------------------------------------
# Regular Colors
Black='\[\033[0;30m\]'
Red='\[\033[0;31m\]'
Green='\[\033[0;32m\]'
Yellow='\[\033[0;33m\]'
Blue='\[\033[0;34m\]'
Purple='\[\033[0;35m\]'
Cyan='\[\033[0;36m\]'
White='\[\033[0;37m\]'
Light_Gray='\[\033[0;37m\]'
# Reset colors
NONE='\[\033[0;0m\]'
# When in a git repo, this method is used to determine the current branch
function parse_git_branch {
git branch 2>/dev/null | grep '^*' | sed 's_^..__' | sed 's_\(.*\)_(\1)_'
}
# When in a git repo, this method is used to determine if there are changes
# Changes will be indicated in the prompt by a *
function git_dirty {
if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then
echo "*"
else
echo ""
fi
}
# Design the prompt
export PS1="$Purple\w$NONE \$(parse_git_branch)$Red \$(git_dirty) $NONE\$ "
# \w shows the current path
# List of other placeholders you can use:
# http://www.gnu.org/software/bash/manual/bash.html#Controlling-the-Prompt
# ------------------------------------
# ALIASES
# ------------------------------------
# Edit .bash_profile
alias configedit='code ~/.bash_profile'
# Force terminal to recognize changes to .bash_profile
alias configrefresh='source ~/.bash_profile'
# Ideal directory listing
alias ll="ls -laFG"
# Ask before removing files
alias rm='rm -i'
# Add your own aliases here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment