From 47022832800f1b224fe6119a1a793aafaa2a8b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Smyku=C5=82a?= Date: Tue, 18 Jun 2013 21:49:53 +0200 Subject: [PATCH] Less code is better, __fish_git_prompt_validate_colors refactor --- share/functions/__fish_git_prompt.fish | 150 ++++++------------------- 1 file changed, 33 insertions(+), 117 deletions(-) diff --git a/share/functions/__fish_git_prompt.fish b/share/functions/__fish_git_prompt.fish index 0e7ed6f37..bef8753c6 100644 --- a/share/functions/__fish_git_prompt.fish +++ b/share/functions/__fish_git_prompt.fish @@ -491,124 +491,40 @@ function __fish_git_prompt_validate_chars --description "__fish_git_prompt helpe end end +function __fish_git_prompt_set_color + set -l user_variable_name "$argv[1]" + set -l variable _$user_variable_name + set -l variable_done "$variable"_done + set -l user_variable $$user_variable_name + + if not set -q $variable + if test -n "$user_variable" + set -g $variable (set_color $user_variable) + set -g $variable_done (set_color normal) + else + set -g $variable '' + set -g $variable_done '' + end + end + +end + function __fish_git_prompt_validate_colors --description "__fish_git_prompt helper, checks color variables" - if not set -q ___fish_git_prompt_color - if test -n "$__fish_git_prompt_color" - set -g ___fish_git_prompt_color (set_color $__fish_git_prompt_color) - set -g ___fish_git_prompt_color_done (set_color normal) - else - set -g ___fish_git_prompt_color '' - set -g ___fish_git_prompt_color_done '' - end - end - if not set -q ___fish_git_prompt_color_prefix - if test -n "$__fish_git_prompt_color_prefix" - set -g ___fish_git_prompt_color_prefix (set_color $__fish_git_prompt_color_prefix) - set -g ___fish_git_prompt_color_prefix_done (set_color normal) - else - set -g ___fish_git_prompt_color_prefix $___fish_git_prompt_color - set -g ___fish_git_prompt_color_prefix_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_suffix - if test -n "$__fish_git_prompt_color_suffix" - set -g ___fish_git_prompt_color_suffix (set_color $__fish_git_prompt_color_suffix) - set -g ___fish_git_prompt_color_suffix_done (set_color normal) - else - set -g ___fish_git_prompt_color_suffix $___fish_git_prompt_color - set -g ___fish_git_prompt_color_suffix_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_bare - if test -n "$__fish_git_prompt_color_bare" - set -g ___fish_git_prompt_color_bare (set_color $__fish_git_prompt_color_bare) - set -g ___fish_git_prompt_color_bare_done (set_color normal) - else - set -g ___fish_git_prompt_color_bare $___fish_git_prompt_color - set -g ___fish_git_prompt_color_bare_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_merging - if test -n "$__fish_git_prompt_color_merging" - set -g ___fish_git_prompt_color_merging (set_color $__fish_git_prompt_color_merging) - set -g ___fish_git_prompt_color_merging_done (set_color normal) - else - set -g ___fish_git_prompt_color_merging $___fish_git_prompt_color - set -g ___fish_git_prompt_color_merging_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_branch - if test -n "$__fish_git_prompt_color_branch" - set -g ___fish_git_prompt_color_branch (set_color $__fish_git_prompt_color_branch) - set -g ___fish_git_prompt_color_branch_done (set_color normal) - else - set -g ___fish_git_prompt_color_branch $___fish_git_prompt_color - set -g ___fish_git_prompt_color_branch_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_cleanstate - if test -n "$__fish_git_prompt_color_cleanstate" - set -g ___fish_git_prompt_color_cleanstate (set_color $__fish_git_prompt_color_cleanstate) - set -g ___fish_git_prompt_color_cleanstate_done (set_color normal) - else - set -g ___fish_git_prompt_color_cleanstate $___fish_git_prompt_color - set -g ___fish_git_prompt_color_cleanstate_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_dirtystate - if test -n "$__fish_git_prompt_color_dirtystate" - set -g ___fish_git_prompt_color_dirtystate (set_color $__fish_git_prompt_color_dirtystate) - set -g ___fish_git_prompt_color_dirtystate_done (set_color normal) - else - set -g ___fish_git_prompt_color_dirtystate $___fish_git_prompt_color - set -g ___fish_git_prompt_color_dirtystate_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_stagedstate - if test -n "$__fish_git_prompt_color_stagedstate" - set -g ___fish_git_prompt_color_stagedstate (set_color $__fish_git_prompt_color_stagedstate) - set -g ___fish_git_prompt_color_stagedstate_done (set_color normal) - else - set -g ___fish_git_prompt_color_stagedstate $___fish_git_prompt_color - set -g ___fish_git_prompt_color_stagedstate_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_invalidstate - if test -n "$__fish_git_prompt_color_invalidstate" - set -g ___fish_git_prompt_color_invalidstate (set_color $__fish_git_prompt_color_invalidstate) - set -g ___fish_git_prompt_color_invalidstate_done (set_color normal) - else - set -g ___fish_git_prompt_color_invalidstate $___fish_git_prompt_color - set -g ___fish_git_prompt_color_invalidstate_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_stashstate - if test -n "$__fish_git_prompt_color_stashstate" - set -g ___fish_git_prompt_color_stashstate (set_color $__fish_git_prompt_color_stashstate) - set -g ___fish_git_prompt_color_stashstate_done (set_color normal) - else - set -g ___fish_git_prompt_color_stashstate $___fish_git_prompt_color - set -g ___fish_git_prompt_color_stashstate_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_untrackedfiles - if test -n "$__fish_git_prompt_color_untrackedfiles" - set -g ___fish_git_prompt_color_untrackedfiles (set_color $__fish_git_prompt_color_untrackedfiles) - set -g ___fish_git_prompt_color_untrackedfiles_done (set_color normal) - else - set -g ___fish_git_prompt_color_untrackedfiles $___fish_git_prompt_color - set -g ___fish_git_prompt_color_untrackedfiles_done $___fish_git_prompt_color_done - end - end - if not set -q ___fish_git_prompt_color_upstream - if test -n "$__fish_git_prompt_color_upstream" - set -g ___fish_git_prompt_color_upstream (set_color $__fish_git_prompt_color_upstream) - set -g ___fish_git_prompt_color_upstream_done (set_color normal) - else - set -g ___fish_git_prompt_color_upstream $___fish_git_prompt_color - set -g ___fish_git_prompt_color_upstream_done $___fish_git_prompt_color_done - end - end + + __fish_git_prompt_set_color __fish_git_prompt_color + __fish_git_prompt_set_color __fish_git_prompt_color_prefix + __fish_git_prompt_set_color __fish_git_prompt_color_suffix + __fish_git_prompt_set_color __fish_git_prompt_color_bare + __fish_git_prompt_set_color __fish_git_prompt_color_merging + __fish_git_prompt_set_color __fish_git_prompt_color_branch + __fish_git_prompt_set_color __fish_git_prompt_color_cleanstate + __fish_git_prompt_set_color __fish_git_prompt_color_dirtystate + __fish_git_prompt_set_color __fish_git_prompt_color_stagedstate + __fish_git_prompt_set_color __fish_git_prompt_color_invalidstate + __fish_git_prompt_set_color __fish_git_prompt_color_stashstate + __fish_git_prompt_set_color __fish_git_prompt_color_untrackedfiles + __fish_git_prompt_set_color __fish_git_prompt_color_upstream + end set -l varargs