Last active
May 7, 2018 16:03
-
-
Save luciopaiva/40c0a827bf3a42641927094d5c48f094 to your computer and use it in GitHub Desktop.
Helpful bash additions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## partial history search (https://askubuntu.com/a/475614/204815) | |
bind '"\e[A":history-search-backward' | |
bind '"\e[B":history-search-forward' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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