diff --git a/README.md b/README.md index a2de364..0275a31 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ The prompt may look like the following: * ``(status|●2)``: on branch ``status``, 2 files staged * ``(master|✚7…)``: on branch ``master``, 7 files changed, some files untracked * ``(master|✖2✚3)``: on branch ``master``, 2 conflicts, 3 files changed +* ``(master|⚑2)``: on branch ``master``, 2 stash entries * ``(experimental↓2↑3|✔)``: on branch ``experimental``; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean * ``(:70c2952|✔)``: not on any branch; parent commit has hash ``70c2952``; the repository is otherwise clean @@ -34,6 +35,7 @@ The symbols are as follows: - ``✖n``: there are ``n`` unmerged files - ``✚n``: there are ``n`` changed but *unstaged* files - ``…n``: there are ``n`` untracked files + - ``⚑n``: there are ``n`` stash entries - Branch Tracking Symbols - ``↑n``: ahead of remote by ``n`` commits - ``↓n``: behind remote by ``n`` commits diff --git a/gitprompt.sh b/gitprompt.sh index 17bb5da..7d6cd3e 100644 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -53,6 +53,7 @@ function git_prompt_config() GIT_PROMPT_CHANGED="${Blue}✚ " GIT_PROMPT_REMOTE=" " GIT_PROMPT_UNTRACKED="…" + GIT_PROMPT_STASHED="⚑ " GIT_PROMPT_CLEAN="${BoldGreen}✔" # Various variables you might want for your PS1 prompt instead @@ -128,6 +129,7 @@ function updatePrompt() { local GIT_PROMPT_CHANGED local GIT_PROMPT_REMOTE local GIT_PROMPT_UNTRACKED + local GIT_PROMPT_STASHED local GIT_PROMPT_CLEAN local PROMPT_START local PROMPT_END @@ -151,7 +153,8 @@ function updatePrompt() { local GIT_CONFLICTS=${GitStatus[3]} local GIT_CHANGED=${GitStatus[4]} local GIT_UNTRACKED=${GitStatus[5]} - local GIT_CLEAN=${GitStatus[6]} + local GIT_STASHED=${GitStatus[6]} + local GIT_CLEAN=${GitStatus[7]} if [[ -n "${GitStatus}" ]]; then local STATUS=" ${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" @@ -177,6 +180,10 @@ function updatePrompt() { STATUS="${STATUS}${GIT_PROMPT_UNTRACKED}${GIT_UNTRACKED}${ResetColor}" fi + if [ "${GIT_STASHED}" -ne "0" ]; then + STATUS="${STATUS}${GIT_PROMPT_STASHED}${GIT_STASHED}${ResetColor}" + fi + if [ "${GIT_CLEAN}" -eq "1" ]; then STATUS="${STATUS}${GIT_PROMPT_CLEAN}" fi diff --git a/gitstatus.py b/gitstatus.py index 63b0b0c..a18e72d 100755 --- a/gitstatus.py +++ b/gitstatus.py @@ -31,8 +31,8 @@ except SyntaxError: w(sep) w(str(a)) w(kwd.get("end", "\n")) - - + + # change those symbols to whatever you prefer symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash':':'} @@ -67,7 +67,11 @@ status_lines = Popen(['git','status','-s','-uall'],stdout=PIPE).communicate()[0] untracked_lines = [a for a in status_lines if a.startswith("??")] nb_untracked = len(untracked_lines) untracked = str(nb_untracked) -if not nb_changed and not nb_staged and not nb_U and not nb_untracked: +stashes = Popen(['git','stash','list'],stdout=PIPE).communicate()[0].splitlines() +nb_stashed = len(stashes) +stashed = str(nb_stashed) + +if not nb_changed and not nb_staged and not nb_U and not nb_untracked and not nb_stashed: clean = '1' else: clean = '0' @@ -115,5 +119,6 @@ out = '\n'.join([ conflicts, changed, untracked, + stashed, clean]) Print(out)