Last active
July 14, 2016 22:40
-
-
Save ramonfritsch/4c05c8dc4a98230043554e731bab6fb6 to your computer and use it in GitHub Desktop.
My cool bash prompt
This file contains hidden or 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 sc_info() { | |
local sc_type=false | |
local sc_branch | |
local sc_dirty=0 | |
if [[ -f .git/HEAD || -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then | |
# elif which git &> /dev/null && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then | |
sc_type="git" | |
local ref=$(git symbolic-ref -q HEAD 2> /dev/null) | |
if [[ -n "$ref" ]]; then | |
sc_branch=${ref#refs/heads/} | |
fi | |
if [[ "$(git config --get bash-it.hide-status)" != "1" ]]; then | |
# local git_status_flags='-uno' # ignore untracked | |
local git_status_flags='' | |
local status_lines=$( (git status --porcelain ${git_status_flags} -b 2> /dev/null || git status --porcelain ${git_status_flags} 2> /dev/null) | git_status_summary) | |
local status=$(awk 'NR==1' <<< "$status_lines") | |
local counts=$(awk 'NR==2' <<< "$status_lines") | |
IFS=$'\t' read untracked_count unstaged_count staged_count <<< "$counts" | |
if [[ "${untracked_count}" -gt 0 || "${unstaged_count}" -gt 0 || "${staged_count}" -gt 0 ]]; then | |
sc_dirty=1 | |
fi | |
fi | |
fi | |
if [[ -d .svn || $(svn info . 2> /dev/null | wc -l) -gt 0 ]]; then | |
sc_type="svn" | |
sc_branch=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return | |
if [[ -n $(svn status -q 2> /dev/null) ]]; then | |
sc_dirty=1 | |
fi | |
fi | |
if [[ "$sc_type" != false ]]; then | |
# echo -en " \033[1;94mgit:$(__git_ps1)\033[0m" | |
echo -en " \033[1;94m${sc_type}:(\033[1;91m${sc_branch}\033[1;94m)" | |
if [[ "${sc_dirty}" -gt 0 ]]; then | |
echo -en " \033[1;93m✗" | |
# else | |
# echo -en " \033[1;92m✓" | |
fi | |
echo -en "\033[0m" | |
fi | |
} | |
function git_status_summary() { | |
awk ' | |
BEGIN { | |
untracked=0; | |
unstaged=0; | |
staged=0; | |
} | |
{ | |
if (!after_first && $0 ~ /^##.+/) { | |
print $0 | |
seen_header = 1 | |
} else if ($0 ~ /^\?\? .+/) { | |
untracked += 1 | |
} else { | |
if ($0 ~ /^.[^ ] .+/) { | |
unstaged += 1 | |
} | |
if ($0 ~ /^[^ ]. .+/) { | |
staged += 1 | |
} | |
} | |
after_first = 1 | |
} | |
END { | |
if (!seen_header) { | |
} | |
print untracked "\t" unstaged "\t" staged | |
}' | |
} | |
function colored_exit_arrow() { | |
if [[ $1 -eq 0 ]]; then | |
echo -en " \033[1;92m➜\033[0m" | |
else | |
echo -en " \033[1;91m➜\033[0m" | |
fi | |
} | |
export CLICOLOR=1 | |
export LSCOLORS=ExFxBxDxCxegedabagacad | |
export PS1="\[\$(colored_exit_arrow $?) \[\e[0;96m\]\w\[\e[0m\]\$(sc_info)\[\e[0m\] " #"\[\e[2;15m\] \$\[\e[0m\] " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment