Skip to content
Snippets Groups Projects
Commit 3eb39969 authored by Ayaz Badouraly's avatar Ayaz Badouraly
Browse files
parent 8ed21d95
Branches
No related tags found
No related merge requests found
#
# functions/utils.zsh - provide useful functions
#
# This work is free. You can redistribute it and/or modify it under the terms of
# the Do What The Fuck You Want To Public License, Version 2, as published by Sam
# Hocevar. See the COPYING file or http://www.wtfpl.net/ for more details.
#
# Given the name of a variable and a default value, sets the variable value to the
# default if and only if it has not been defined.
#
# @param $1 : name of the variable to be filled
# @param $2 : default value set if $1 is not already defined
function set_default() {
# /!\ compute differently with color variables
# TODO make the regex case-insensitive
if [[ $1 =~ '_COLOR(_.*)?$' ]]; then
set_default_color $1 $2
else
# See http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
[[ -z ${(P)1} ]] && typeset -g $1=$2
fi
}
# Given the name of a variable and a default value, overwrites the variable value
# if and only if it has not been properly set as a visual effect.
#
# @param $1 : name of the variable to be filled
# @param $2 : default value set if $1 is not already a visual effect or a color code
function set_default_color() {
# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Visual-effects
if [[ ! ${(P)1} =~ '%' ]]; then
# If the variable whose name is $1 has already been overwritten,
# use this color instead of the default one provided in $2
if [[ -n ${(P)1} ]]; then
typeset -g $1="%F{${(P)1}}"
else
# Distinguish case in which $2 is already a visual effect
# and case in which it is only a color code
if [[ $2 =~ '%' ]]; then
typeset -g $1=$2
else
typeset -g $1="%F{$2}"
fi
fi
fi
}
# vim: ft=zsh fenc=utf-8
......@@ -13,6 +13,7 @@
OHMYVIA_INSTALLATION_PATH="$(dirname "$0")"
source $OHMYVIA_INSTALLATION_PATH/functions/utils.zsh
source $OHMYVIA_INSTALLATION_PATH/functions/vcs_themes.zsh
source $OHMYVIA_INSTALLATION_PATH/functions/vcs_utils.zsh
......@@ -49,11 +50,11 @@ zstyle ':vcs_info:*' max-exports 1 # vcs_info only sets vcs_info_msg_0_
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' check-for-changes true # enable %c and %u sequences usage
OHMYVIA_VCS_COLOR_UNSTAGED=${OHMYVIA_VCS_COLOR_UNSTAGED:-"%F{red}"}
OHMYVIA_VCS_COLOR_STAGED=${OHMYVIA_VCS_COLOR_STAGED:-"%F{yellow}"}
OHMYVIA_VCS_COLOR_UNTRACKED=${OHMYVIA_VCS_COLOR_UNTRACKED:-"%F{blue}"}
OHMYVIA_VCS_COLOR_STASH=${OHMYVIA_VCS_COLOR_STASH:-"%F{cyan}"}
OHMYVIA_VCS_COLOR_CLEAN=${OHMYVIA_VCS_COLOR_CLEAN:-"%F{green}"}
set_default OHMYVIA_VCS_COLOR_UNSTAGED "red"
set_default OHMYVIA_VCS_COLOR_STAGED "yellow"
set_default OHMYVIA_VCS_COLOR_UNTRACKED "blue"
set_default OHMYVIA_VCS_COLOR_STASH "cyan"
set_default OHMYVIA_VCS_COLOR_CLEAN "green"
zstyle ':vcs_info:*' unstagedstr $OHMYVIA_VCS_COLOR_UNSTAGED
zstyle ':vcs_info:*' stagedstr $OHMYVIA_VCS_COLOR_STAGED
......@@ -61,7 +62,7 @@ zstyle ':vcs_info:*' stagedstr $OHMYVIA_VCS_COLOR_STAGED
zstyle ':vcs_info:git*+set-message:*' hooks misc-init git-stash git-untracked
# Load VCS theme
OHMYVIA_VCS_THEME=${OHMYVIA_VCS_THEME:-"default"}
set_default OHMYVIA_VCS_THEME "default"
eval +vi-theme-$OHMYVIA_VCS_THEME
zstyle ':vcs_info:*' formats " $OHMYVIA_VCS_PROMPT_NORMAL"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment