omg/prompt.sh
fcamblor 47b1a37420 Added --pretty=oneline to commit aa63017ad0
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Sun Sep 8 13:03:32 2013 +0200

    By default does not print a symbol when the correspondent flag is false

commit f2e3a20c19
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Thu Sep 5 22:12:34 2013 +0200

    tag symbol is close to tag name

commit 5818883195
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Thu Sep 5 08:29:12 2013 +0200

    It does not fire any errors when in a brand new repository

commit 7d8f4eac04
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Fri Sep 6 17:03:07 2013 +0200

    Shut up and take my money is an animated gif

commit fbd9341c64
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Fri Sep 6 15:44:54 2013 +0200

    "Known bugs" specifies the need for an unicode font

commit b135765cab
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Fri Sep 6 15:20:39 2013 +0200

    Update README.md

    README.md has "Installation", "Known bugs" and "zsh version" sections

commit 966c06ab9f
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Fri Sep 6 15:01:49 2013 +0200

    README.md has all the sample images

commit e7a7c07427
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Wed Sep 4 22:56:51 2013 +0200

    Is a git repo has a violet symbol

commit 249b717000
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Wed Sep 4 22:36:13 2013 +0200

    a star is displayed when stash list is not empty

commit 87a75f7d77
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Wed Sep 4 22:28:03 2013 +0200

    detached symbol is not overwritten

commit 475805526b
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Wed Sep 4 20:17:21 2013 +0200

    number of ahead/behind commits, should push, can fast forward and has diverged sybols are set correctly

commit 8d32b73a46
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Wed Sep 4 08:47:18 2013 +0200

    When not in a git repo, the prompt does not use two lines

commit fc42bd7a57
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Wed Sep 4 08:45:20 2013 +0200

    Has modifications cached has a nicer symbol

commit 5c0092061d
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Wed Sep 4 08:38:57 2013 +0200

    ready to commit is displayed only when no files are left to cache

commit 20e74a8159
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Wed Sep 4 08:13:30 2013 +0200

    when browsing bash history the cursor is no shifted anymore

commit d8b3c75047
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 23:35:13 2013 +0200

    tags are detected correctly

commit dd7f87d054
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 23:20:44 2013 +0200

    tag in last position; has diverged and can fast-forward work

commit bd94ce0058
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 22:02:15 2013 +0200

    the number of commits behind or ahead is correct even after a push

commit 71d2975e6a
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 19:11:22 2013 +0200

    the number of commits from or to the remote branch is correctly calculated

commit c6e25a79c0
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 18:47:06 2013 +0200

    display of tag name is optional

commit 48ccb29b25
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 18:41:00 2013 +0200

    if on a tag, it displays a symbol and the tag name

commit 05577400d6
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 09:14:58 2013 +0200

    it doesn't display an extra space if  no ahead/behind message needs to be printed

commit 745bb609f8
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 08:57:36 2013 +0200

    Shows how many commits the branch is behind or ahead its upstream

commit 9b972b6143
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 08:35:50 2013 +0200

    Symbols can be overwritten

commit a7d727b800
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 07:54:15 2013 +0200

    The prompt is displayed in two lines

commit 27f6403382
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Sep 3 07:47:52 2013 +0200

    fake Will merge, will rebase

commit a48b0acabd
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 23:27:36 2013 +0200

    Support for just initialized repositories

commit 694e1f854e
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 22:59:09 2013 +0200

    It displays added and removed files

commit f254267b28
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 20:11:54 2013 +0200

    if upstream branch has the same name as the local one, the name is omitted

commit d86af5c1e9
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 19:15:33 2013 +0200

    The upstream branch is shown

commit c397ff3c92
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 19:12:27 2013 +0200

    Using only enrich

commit 064812ae41
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 19:00:26 2013 +0200

    refactoring

commit c1fc8c0151
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 08:49:50 2013 +0200

    one-line if-then-elses

commit bb9e173fd2
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 08:31:05 2013 +0200

    Refactoring, partly working

commit e51614216b
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 00:59:21 2013 +0200

    Flags for modifications, indexed and untracked

commit 12360123b4
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Mon Sep 2 00:02:16 2013 +0200

    Displays a yellow heart if the current directory is a git repository

commit 5ad1ac07bb
Author: Arialdo Martini <arialdomartini@gmail.com>
Date:   Tue Aug 20 06:52:00 2013 -0700

    Initial commit for commits counts
2013-09-11 17:59:28 +02:00

203 lines
7.8 KiB
Bash

function enrich {
flag=$1
symbol=$2
if [[ -n $3 ]]
then
coloron=$3
else
coloron=${on}
fi
if [ ${use_color_off} == false -a ${flag} == false ]; then symbol=" "; fi
if [[ $flag == true ]]; then color="${coloron}"; else color="${off}"; fi
PS1="${PS1}${color}${symbol}${reset} "
}
function build_prompt {
PS1=""
# Symbols
if [[ -z "${is_a_git_repo_symbol}" ]]; then is_a_git_repo_symbol="❤"; fi
if [[ -z "${has_untracked_files_symbol}" ]]; then has_untracked_files_symbol="∿"; fi
if [[ -z "${has_adds_symbol}" ]]; then has_adds_symbol="+"; fi
if [[ -z "${has_deletions_symbol}" ]]; then has_deletions_symbol="-"; fi
if [[ -z "${has_deletions_cached_symbol}" ]]; then has_deletions_cached_symbol="✖"; fi
if [[ -z "${has_modifications_symbol}" ]]; then has_modifications_symbol="✎"; fi
if [[ -z "${has_modifications_cached_symbol}" ]]; then has_modifications_cached_symbol="☲"; fi
if [[ -z "${ready_to_commit_symbol}" ]]; then ready_to_commit_symbol="→"; fi
if [[ -z "${is_on_a_tag_symbol}" ]]; then is_on_a_tag_symbol="⌫"; fi
if [[ -z "${needs_to_merge_symbol}" ]]; then needs_to_merge_symbol="ᄉ"; fi
if [[ -z "${has_upstream_symbol}" ]]; then has_upstream_symbol="⇅"; fi
if [[ -z "${detached_symbol}" ]]; then detached_symbol="⚯"; fi
if [[ -z "${can_fast_forward_symbol}" ]]; then can_fast_forward_symbol="»"; fi
if [[ -z "${has_diverged_symbol}" ]]; then has_diverged_symbol="Ⴤ"; fi
if [[ -z "${rebase_tracking_branch_symbol}" ]]; then rebase_tracking_branch_symbol="↶"; fi
if [[ -z "${merge_tracking_branch_symbol}" ]]; then merge_tracking_branch_symbol="ᄉ"; fi
if [[ -z "${should_push_symbol}" ]]; then should_push_symbol="↑"; fi
if [[ -z "${has_stashes_symbol}" ]]; then has_stashes_symbol="★"; fi
# flags
if [[ -z "${display_has_upstream}" ]]; then display_has_upstream=false; fi
if [[ -z "${display_tag}" ]]; then display_tag=false; fi
if [[ -z "${display_tag_name}" ]]; then display_tag_name=true; fi
if [[ -z "${two_lines}" ]]; then two_lines=true; fi
if [[ -z "${finally}" ]]; then finally="\w ∙ "; fi
if [[ -z "${use_color_off}" ]]; then use_color_off=false; fi
# Colors
on="\[\033[0;37m\]"
off="\[\033[1;30m\]"
red="\[\033[0;31m\]"
green="\[\033[0;32m\]"
yellow="\[\033[0;33m\]"
violet="\[\033[0;35m\]"
branch_color="\[\033[0;34m\]"
# blinking="\[\033[1;5;17m\]"
reset="\[\033[0m\]"
# Git info
current_commit_hash=$(git rev-parse HEAD 2> /dev/null)
current_commit_hash_abbrev=$(git rev-parse --short HEAD 2> /dev/null)
if [[ -n $current_commit_hash ]]; then is_a_git_repo=true; else is_a_git_repo=false; fi
number_of_logs=$(git log 2>/dev/null| wc -l)
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null);
if [[ $current_branch == "HEAD" ]]; then detached=true; else detached=false; fi
if [ $is_a_git_repo == true -a $number_of_logs == 0 ]; then just_init=true; fi
if [ $is_a_git_repo == true -a $number_of_logs -gt 0 ]; then
upstream=$(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} 2> /dev/null)
if [[ $upstream != "@{upstream}" ]]; then has_upstream=true; else has_upstream=false; upstream=""; fi
number_of_modifications=$(git status --short 2> /dev/null|grep --count -e ^\.M)
if [[ ${number_of_modifications} -gt 0 ]] ; then has_modifications=true; else has_modifications=false; fi
number_of_modifications_cached=$(git status --short 2> /dev/null|grep --count -e ^M)
if [[ ${number_of_modifications_cached} -gt 0 ]] ; then has_modifications_cached=true; else has_modifications_cached=false; fi
number_of_adds=$(git status --short 2> /dev/null|grep --count -e ^\A)
if [[ ${number_of_adds} -gt 0 ]] ; then has_adds=true; else has_adds=false; fi
number_of_deletions=$(git status --short 2> /dev/null|grep --count -e ^.D)
if [[ ${number_of_deletions} -gt 0 ]] ; then has_deletions=true; else has_deletions=false; fi
number_of_deletions_cached=$(git status --short 2> /dev/null|grep --count -e ^D)
if [[ ${number_of_deletions_cached} -gt 0 ]] ; then has_deletions_cached=true; else has_deletions_cached=false; fi
numbers_of_files_cached=$(git status --short 2> /dev/null|grep --count -e ^[MAD])
numbers_of_files_not_cached=$(git status --short 2> /dev/null|grep --count -e ^.[MAD\?])
if [ ${numbers_of_files_cached} -gt 0 -a ${numbers_of_files_not_cached} -eq 0 ] ; then ready_to_commit=true; else ready_to_commit=false; fi
number_of_untracked_files=$(git status --short 2> /dev/null|grep --count -e ^\?\?)
if [[ ${number_of_untracked_files} -gt 0 ]] ; then has_untracked_files=true; else has_untracked_files=false; fi
tag_at_current_commit=$(git describe --exact-match --tags ${current_commit_hash} 2>/dev/null)
if [[ -n "${tag_at_current_commit}" ]]; then is_on_a_tag=true; else is_on_a_tag=false; fi;
commits_ahead=0
commits_behind=0
has_diverged=false
can_fast_forward=false
can_fast_forward=false
commits_ahead=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^<" )
commits_behind=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^>" )
if [ ${commits_ahead} -gt 0 -a ${commits_behind} -gt 0 ];
then
has_diverged=true
fi
if [ ${commits_ahead} -eq 0 -a ${commits_behind} -gt 0 ];
then
can_fast_forward=true
fi
will_rebase=$(git config --get branch.${current_branch}.rebase 2>/dev/null)
number_of_stashes=$(git stash list | wc -l)
if [[ ${number_of_stashes} -gt 0 ]]; then has_stashes=true; else has_stashes=false; fi
else
is_on_a_tag=false
fi
if [[ ${is_a_git_repo} == true ]]
then
enrich ${is_a_git_repo} "${is_a_git_repo_symbol}" "${violet}"
enrich ${has_stashes} "${has_stashes_symbol}" "${yellow}"
enrich ${has_untracked_files} "${has_untracked_files_symbol}" "${red}"
enrich ${has_adds} "${has_adds_symbol}" "${yellow}"
enrich ${has_deletions} "${has_deletions_symbol}" "${red}"
enrich ${has_deletions_cached} "${has_deletions_cached_symbol}" "${yellow}"
enrich ${has_modifications} "${has_modifications_symbol}" "${red}"
enrich ${has_modifications_cached} "${has_modifications_cached_symbol}" "${yellow}"
enrich ${ready_to_commit} "${ready_to_commit_symbol}" "${green}"
enrich ${detached} "${detached_symbol}" "${red}"
if [[ ${display_has_upstream} == true ]]; then
enrich ${has_upstream} "${has_upstream_symbol}"
fi
if [[ ${detached} == true ]]
then
if [[ ${just_init} == true ]]; then
PS1="${PS1} ${red}detached"
else
PS1="${PS1} ${on}(${current_commit_hash_abbrev})"
fi
else
if [[ $has_upstream == true ]]
then
if [[ ${will_rebase} == true ]];
then
type_of_upstream="${rebase_tracking_branch_symbol}";
else
type_of_upstream="${merge_tracking_branch_symbol}";
fi
if [[ ${has_diverged} == true ]]; then
PS1="${PS1} -${commits_behind} ${has_diverged_symbol} +${commits_ahead}"
else
if [[ ${commits_behind} -gt 0 ]]; then
PS1="${PS1} ${on} -${commits_behind} ${can_fast_forward_symbol} "
fi
if [[ ${commits_ahead} -gt 0 ]]; then
PS1="${PS1} ${on} ${should_push_symbol} +${commits_ahead}"
fi
fi
PS1="${PS1} (${green}${current_branch}${reset} ${type_of_upstream} ${upstream//\/$current_branch/})"
else
PS1="${PS1} ${on}(${green}${current_branch}${reset})"
fi
fi
if [[ ${display_tag} == true ]]; then
PS1="${PS1} ${yellow}${is_on_a_tag_symbol}${reset}"
fi
if [ ${display_tag_name} == true -a ${is_on_a_tag} == true ];
then
PS1="${PS1} ${yellow}[${tag_at_current_commit}]${reset}"
fi
fi
if [ ${two_lines} == true -a ${is_a_git_repo} == true ];
then
break="\n";
else
break="";
fi
PS1="${PS1}${reset}${break}${finally}"
}
PROMPT_COMMAND=build_prompt