diff --git a/modules/git-info/functions/coalesce b/modules/git-info/functions/coalesce index e9e838e..e5f028f 100644 --- a/modules/git-info/functions/coalesce +++ b/modules/git-info/functions/coalesce @@ -1,3 +1,4 @@ +# vim:et sts=2 sw=2 ft=zsh # Prints the first non-empty string in the arguments array. for arg in ${argv}; do print -n ${arg} diff --git a/modules/git-info/functions/git-action b/modules/git-info/functions/git-action new file mode 100644 index 0000000..007da9a --- /dev/null +++ b/modules/git-info/functions/git-action @@ -0,0 +1,80 @@ +# vim:et sts=2 sw=2 ft=zsh +# Gets the Git special action (am, bisect, cherry, merge, rebase). +# Borrowed from vcs_info and edited. +local git_dir=${$(command git rev-parse --git-dir):A} +local action_dir +for action_dir in \ + "${git_dir}/rebase-apply" \ + "${git_dir}/rebase" \ + "${git_dir}/../.dotest" +do + if [[ -d ${action_dir} ]]; then + local apply_formatted rebase_formatted + zstyle -s ':zim:git-info:action:apply' format 'apply_formatted' || apply_formatted='apply' + zstyle -s ':zim:git-info:action:rebase' format 'rebase_formatted' || rebase_formatted='rebase' + + if [[ -f "${action_dir}/rebasing" ]]; then + print ${rebase_formatted} + elif [[ -f "${action_dir}/applying" ]]; then + print ${apply_formatted} + else + print "${rebase_formatted}/${apply_formatted}" + fi + + return 0 + fi +done + +for action_dir in \ + "${git_dir}/rebase-merge/interactive" \ + "${git_dir}/.dotest-merge/interactive" +do + if [[ -f ${action_dir} ]]; then + local rebase_interactive_formatted + zstyle -s ':zim:git-info:action:rebase-interactive' format 'rebase_interactive_formatted' || rebase_interactive_formatted='rebase-interactive' + print ${rebase_interactive_formatted} + return 0 + fi +done + +for action_dir in \ + "${git_dir}/rebase-merge" \ + "${git_dir}/.dotest-merge" +do + if [[ -d ${action_dir} ]]; then + local rebase_merge_formatted + zstyle -s ':zim: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 + local merge_formatted + zstyle -s ':zim: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 + local cherry_pick_sequence_formatted + zstyle -s ':zim:git-info:action:cherry-pick-sequence' format 'cherry_pick_sequence_formatted' || cherry_pick_sequence_formatted='cherry-pick-sequence' + print ${cherry_pick_sequence_formatted} + else + local cherry_pick_formatted + zstyle -s ':zim: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 + local bisect_formatted + zstyle -s ':zim:git-info:action:bisect' format 'bisect_formatted' || bisect_formatted='bisect' + print ${bisect_formatted} + return 0 +fi + +return 1 diff --git a/modules/git-info/functions/git-info b/modules/git-info/functions/git-info index 6cd0d28..4d4b55b 100644 --- a/modules/git-info/functions/git-info +++ b/modules/git-info/functions/git-info @@ -31,88 +31,6 @@ fi local action_format action_formatted zstyle -s ':zim:git-info:action' format 'action_format' if [[ -n ${action_format} ]]; then - # Gets the Git special action (am, bisect, cherry, merge, rebase). - # Borrowed from vcs_info and edited. - git-action() { - local git_dir=${$(command git rev-parse --git-dir):A} - local action_dir - for action_dir in \ - "${git_dir}/rebase-apply" \ - "${git_dir}/rebase" \ - "${git_dir}/../.dotest" - do - if [[ -d ${action_dir} ]]; then - local apply_formatted rebase_formatted - zstyle -s ':zim:git-info:action:apply' format 'apply_formatted' || apply_formatted='apply' - zstyle -s ':zim:git-info:action:rebase' format 'rebase_formatted' || rebase_formatted='rebase' - - if [[ -f "${action_dir}/rebasing" ]]; then - print ${rebase_formatted} - elif [[ -f "${action_dir}/applying" ]]; then - print ${apply_formatted} - else - print "${rebase_formatted}/${apply_formatted}" - fi - - return 0 - fi - done - - for action_dir in \ - "${git_dir}/rebase-merge/interactive" \ - "${git_dir}/.dotest-merge/interactive" - do - if [[ -f ${action_dir} ]]; then - local rebase_interactive_formatted - zstyle -s ':zim:git-info:action:rebase-interactive' format 'rebase_interactive_formatted' || rebase_interactive_formatted='rebase-interactive' - print ${rebase_interactive_formatted} - return 0 - fi - done - - for action_dir in \ - "${git_dir}/rebase-merge" \ - "${git_dir}/.dotest-merge" - do - if [[ -d ${action_dir} ]]; then - local rebase_merge_formatted - zstyle -s ':zim: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 - local merge_formatted - zstyle -s ':zim: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 - local cherry_pick_sequence_formatted - zstyle -s ':zim:git-info:action:cherry-pick-sequence' format 'cherry_pick_sequence_formatted' || cherry_pick_sequence_formatted='cherry-pick-sequence' - print ${cherry_pick_sequence_formatted} - else - local cherry_pick_formatted - zstyle -s ':zim: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 - local bisect_formatted - zstyle -s ':zim:git-info:action:bisect' format 'bisect_formatted' || bisect_formatted='bisect' - print ${bisect_formatted} - return 0 - fi - - return 1 - } - local action=$(git-action) if [[ -n ${action} ]]; then zformat -f action_formatted ${action_format} "s:${action}"