Skip to content

Instantly share code, notes, and snippets.

@luciopaiva
Last active May 7, 2018
Embed
What would you like to do?
Helpful bash additions
_ _
| | (_)
| |_ _ ___ _ ___
| | | | |/ __| |/ _ \
| | |_| | (__| | (_) |
|_|\__,_|\___|_|\___/
# Helpful bash aliases
#
# Paste this into `~/.bash_aliases`:
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../../"
alias .....="cd ../../../.."
alias ~="cd"
# alias to reload bashrc after changes
alias rebash="source ~/.bashrc"
alias g="git"
alias gt="git"
# Show welcome banner
function show_banner {
local output=$(cat ~/.banner)
echo -e "$COLOR_Y$output$COLOR_RESET"
echo ""
}
show_banner
# Prompt with git status
# regular colors
COLOR_K="\033[0;30m" # black
COLOR_R="\033[0;31m" # red
COLOR_G="\033[0;32m" # green
COLOR_Y="\033[0;33m" # yellow
COLOR_B="\033[0;34m" # blue
COLOR_M="\033[0;35m" # magenta
COLOR_C="\033[0;36m" # cyan
COLOR_W="\033[0;37m" # white
# emphasized (bolded) colors
COLOR_BK="\033[1;30m"
COLOR_BR="\033[1;31m"
COLOR_BG="\033[1;32m"
COLOR_BY="\033[1;33m"
COLOR_BB="\033[1;34m"
COLOR_BM="\033[1;35m"
COLOR_BC="\033[1;36m"
COLOR_BW="\033[1;37m"
# reset
COLOR_RESET="\033[00m"
function git_prompt_status {
local index=$(git status --porcelain 2> /dev/null)
local status=""
local red_flag="$COLOR_R⚑$COLOR_RESET "
local yellow_flag="$COLOR_Y⚑$COLOR_RESET "
local green_flag="$COLOR_G⚑$COLOR_RESET "
# conflicted
if $(echo "$index" | grep '^UU ' &> /dev/null); then
status="$red_flag$status"
fi
# work tree only
if $(echo "$index" | grep '^.[MD] ' &> /dev/null); then
status="$yellow_flag$status"
elif $(echo "$index" | grep '^?? ' &> /dev/null); then
status="$yellow_flag$status"
fi
# indexed
if $(echo "$index" | grep '^[AMDR]. ' &> /dev/null); then
status="$green_flag$status"
fi
# remove last space
status=$(echo -ne $status | sed -E "s/\s$//g")
echo -ne $status
}
function git_prompt {
(git root > /dev/null 2>&1)
# check output. if zero, we have a git repo
if [ "$?" -eq "0" ]; then
local repo_name="$(git currentbranch 2> /dev/null)"
echo -e " on ${COLOR_M}${repo_name}${COLOR_RESET}$(git_prompt_status)"
else
echo ""
fi
}
PS1="\${debian_chroot:+(\$debian_chroot)}${COLOR_BG}\u$COLOR_RESET:$COLOR_BB\w$COLOR_RESET\$(git_prompt)\n$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment