diff --git a/modules/git/README.md b/modules/git/README.md index 70180c8..23049ee 100644 --- a/modules/git/README.md +++ b/modules/git/README.md @@ -3,7 +3,10 @@ Git Provides nice git aliases and functions. -Many thanks to [Sorin Ionescu](https://github.com/sorin-ionescu) for these. +Also provides functions necessary for many prompts. + +Many thanks to [Sorin Ionescu](https://github.com/sorin-ionescu) for the excellent aliases. + Aliases ------- @@ -203,6 +206,7 @@ You can temporarily bypass an alias by prefixing it with a backward slash: Functions --------- + General: - `git-branch-current` displays the current branch. - `git-commit-lost` lists lost commits. - `git-dir` displays the path to the Git directory. @@ -215,3 +219,7 @@ Functions - `git-stash-recover` recovers given dropped stashed states. - `git-submodule-move` moves a submodule. - `git-submodule-remove` removes a submodule. + + Prompt: + - `git_prompt_info` provides git information to oh-my-zsh sourced prompts. + - `parse-git-dirty` needed for `git-prompt-info` to check if repo is dirty. diff --git a/modules/git/functions/git_prompt_info b/modules/git/functions/git_prompt_info new file mode 100644 index 0000000..2eb7413 --- /dev/null +++ b/modules/git/functions/git_prompt_info @@ -0,0 +1,8 @@ +# slightly modified git_prompt_info from oh-my-zsh for theme compatibility + +local ref +if [[ ${zgit_hide_prompt} != 'true' ]]; then + ref=$(command git symbolic-ref HEAD 2> /dev/null) || \ + ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0 + print "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" +fi diff --git a/modules/git/functions/parse_git_dirty b/modules/git/functions/parse_git_dirty new file mode 100644 index 0000000..9de07f4 --- /dev/null +++ b/modules/git/functions/parse_git_dirty @@ -0,0 +1,18 @@ +# slightly modified parse_git_dirty from oh-my-zsh for theme compatibility +# not supporting git < 1.7.2; upgrade your shit + +local STATUS='' +local FLAGS=('--porcelain' '--ignore-submodules=dirty') +if [[ ${zgit_hide_prompt} != 'true' ]]; then + if [[ "$zgit_disable_untracked_dirty" == "true" ]]; then + FLAGS+='--untracked-files=no' + fi + STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1) +fi +if [[ -n $STATUS ]]; then + print ${ZSH_THEME_GIT_PROMPT_DIRTY} +else + print ${ZSH_THEME_GIT_PROMPT_CLEAN} +fi + +#unset FLAGS STATUS