Created
October 20, 2016 19:56
-
-
Save jorke/5268f6359975568e381426f75d768389 to your computer and use it in GitHub Desktop.
bash prompt
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
function confirm () { | |
# call with a prompt string or use a default | |
read -r -p "${1:-Are you sure? [y/N]} " response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
true | |
;; | |
*) | |
false | |
;; | |
esac | |
} | |
function git-delete-branch () { | |
if [ "$#" -ne 1 ]; then | |
printf "Usage: $FUNCNAME branchName\nWill delete the specified branch from both the local repository and remote\n"; | |
return 1; | |
fi | |
echo "Delete the branch '$1' from your local repository?" && confirm && git branch -d $1; | |
echo "Delete the branch '$1' from the remote repository?" && confirm && git push origin --delete $1; | |
} | |
function git-delete-merged-branches () { | |
echo && \ | |
echo "Branches that are already merged into $(git rev-parse --abbrev-ref HEAD) and will be deleted from both local and remote:" && \ | |
echo && \ | |
git branch --merged | grep feature && \ | |
echo && \ | |
confirm && git branch --merged | grep feature | xargs -n1 -I '{}' sh -c "git push origin --delete '{}'; git branch -d '{}';" | |
} | |
# source ~/.git-prompt.sh | |
function color_my_prompt { | |
local __user_and_host="\[\033[01;32m\]\u@\h" | |
local __cur_location="\[\033[01;34m\]\w" | |
local __git_branch_color="\[\033[31m\]" | |
#local __git_branch="\`ruby -e \"print (%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* (.+)$/, '(\1) ')\"\`" | |
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`' | |
local __prompt_tail="\[\033[35m\]$" | |
local __last_color="\[\033[00m\]" | |
local __git_dirty='`git rev-parse 2>/dev/null && (git diff --no-ext-diff --quiet --exit-code 2> /dev/null || echo -e \*)`' | |
export PS1="$__user_and_host $__cur_location $__git_branch_color$__git_branch$__git_dirty$__prompt_tail$__last_color " | |
} | |
color_my_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment