From cfc95cd5ee0f410437d0a6c0585b7c64a8eccc58 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Tue, 2 Oct 2012 14:18:44 -0400 Subject: [PATCH] [Fix #244] Add Git special action styles --- modules/git/README.md | 20 +++++++++++++++++-- modules/git/functions/git-info | 35 +++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/modules/git/README.md b/modules/git/README.md index 262295e..d3ad878 100644 --- a/modules/git/README.md +++ b/modules/git/README.md @@ -241,9 +241,12 @@ Theming ------- To display information about the current repository in a prompt, define the -following styles in the `prompt_name_setup` function. +following styles in the `prompt_name_setup` function, where the syntax for +setting a style is as follows. -| Name | Format Code | Content + zstyle ':prezto:module:git:info:context:subcontext' format 'string' + +| Name | Format Code | Description | --------- | :---------: | --------------------------------------------------- | action | %s | Special action name | added | %a | Added files count @@ -261,6 +264,19 @@ following styles in the `prompt_name_setup` function. | stashed | %S | Stashed states count | unmerged | %U | Unmerged files count | untracked | %u | Untracked files count +[**Main Contexts**] + +| Name | Format | Description +| -------------------- | :---------: | ----------------------------------------- +| apply | value | Applying patches +| bisect | value | Binary searching for changes +| cherry-pick | value | Cherry picking +| cherry-pick-sequence | value | Cherry picking sequence +| merge | value | Merging +| rebase | value | Rebasing +| rebase-interactive | value | Rebasing interactively +| rebase-merge | value | Rebasing merge +[**Special Action Contexts**] First, format the repository state attributes. For example, to format the branch and remote names, define the following styles. diff --git a/modules/git/functions/git-info b/modules/git/functions/git-info index 9c99ad4..2e52eab 100644 --- a/modules/git/functions/git-info +++ b/modules/git/functions/git-info @@ -10,6 +10,14 @@ function _git-action { local action_dir local git_dir="$(git-dir)" + local apply_formatted + local bisect_formatted + local cherry_pick_formatted + local cherry_pick_sequence_formatted + local merge_formatted + local rebase_formatted + local rebase_interactive_formatted + local rebase_merge_formatted for action_dir in \ "${git_dir}/rebase-apply" \ @@ -17,12 +25,15 @@ function _git-action { "${git_dir}/../.dotest" do if [[ -d "$action_dir" ]] ; then + zstyle -s ':prezto:module:git:info:action:apply' format 'apply_formatted' || apply_formatted='apply' + zstyle -s ':prezto:module:git:info:action:rebase' format 'rebase_formatted' || rebase_formatted='rebase' + if [[ -f "${action_dir}/rebasing" ]] ; then - print 'rebase' + print "$rebase_formatted" elif [[ -f "${action_dir}/applying" ]] ; then - print 'am' + print "$apply_formatted" else - print 'am/rebase' + print "${rebase_formatted}/${apply_formatted}" fi return 0 @@ -34,7 +45,8 @@ function _git-action { "${git_dir}/.dotest-merge/interactive" do if [[ -f "$action_dir" ]]; then - print 'rebase-i' + zstyle -s ':prezto:module:git:info:action:rebase-interactive' format 'rebase_interactive_formatted' || rebase_interactive_formatted='rebase-interactive' + print "$rebase_interactive_formatted" return 0 fi done @@ -44,28 +56,33 @@ function _git-action { "${git_dir}/.dotest-merge" do if [[ -d "$action_dir" ]]; then - print 'rebase-m' + zstyle -s ':prezto:module:git:info:action:rebase-merge' format 'rebase_merge_formatted' || rebase_merge_formatted='rebase-merge' + print "$rebase_merge_formatted" return 0 fi done if [[ -f "${git_dir}/MERGE_HEAD" ]]; then - print 'merge' + zstyle -s ':prezto:module:git:info:action:merge' format 'merge_formatted' || merge_formatted='merge' + print "$merge_formatted" return 0 fi if [[ -f "${git_dir}/CHERRY_PICK_HEAD" ]]; then if [[ -d "${git_dir}/sequencer" ]] ; then - print 'cherry-seq' + zstyle -s ':prezto:module:git:info:action:cherry-pick-sequence' format 'cherry_pick_sequence_formatted' || cherry_pick_sequence_formatted='cherry-pick-sequence' + print "$cherry_pick_sequence_formatted" else - print 'cherry' + zstyle -s ':prezto:module:git:info:action:cherry-pick' format 'cherry_pick_formatted' || cherry_pick_formatted='cherry-pick' + print "$cherry_pick_formatted" fi return 0 fi if [[ -f "${git_dir}/BISECT_LOG" ]]; then - print 'bisect' + zstyle -s ':prezto:module:git:info:action:bisect' format 'bisect_formatted' || bisect_formatted='bisect' + print "$bisect_formatted" return 0 fi