diff --git a/README.md b/README.md index 1451babf4dffa794c1931ce8656510a8c64018ef..9748e98e312da0d12c994ebb5d795aeb478e94f1 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ Info | Color | State | Variable | |:------:|:--------------------------:|:-----------------------------:| -| red | there are unstaged files | `OHMYVIA_VCS_UNSTAGED_COLOR` | -| yellow | there are staged files | `OHMYVIA_VCS_STAGED_COLOR` | -| blue | there are untracked files | `OHMYVIA_VCS_UNTRACKED_COLOR` | -| cyan | stash stack is not empty | `OHMYVIA_VCS_STASH_COLOR` | -| green | working directory is clean | `OHMYVIA_VCS_CLEAN_COLOR` | +| red | there are unstaged files | `OHMYVIA_VCS_COLOR_UNSTAGED` | +| yellow | there are staged files | `OHMYVIA_VCS_COLOR_STAGED` | +| blue | there are untracked files | `OHMYVIA_VCS_COLOR_UNTRACKED` | +| cyan | stash stack is not empty | `OHMYVIA_VCS_COLOR_STASH` | +| green | working directory is clean | `OHMYVIA_VCS_COLOR_CLEAN` | Usage @@ -44,6 +44,7 @@ ZSH_THEME="oh-my-via/via" Time format defaults to `%D{%H:%M}`, but can be overwritten by setting the variable `OHMYVIA_TIME_FORMAT` in your `~/.zshrc`. +VCS theme can be set through the variable `OHMYVIA_VCS_THEME`. Testing ------- diff --git a/functions/vcs_themes.zsh b/functions/vcs_themes.zsh new file mode 100644 index 0000000000000000000000000000000000000000..09cf1aa8f32b72019feb7544a90d02cf1653f6d0 --- /dev/null +++ b/functions/vcs_themes.zsh @@ -0,0 +1,72 @@ +# +# functions/vcs_themes.zsh - provide sample themes for VCS prompt +# +# 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. +# + +# In normal formats and actionformats the following replacements are done: +#› %s : The VCS in use (git, hg, svn, etc.). +#› %b : Information about the current branch. +#› %a : An identifier that describes the action. Only makes sense in actionformats. +#› %i : The current revision number or identifier. For hg the hgrevformat style may be used to customize the output. +#› %c : The string from the stagedstr style if there are staged changes in the repository. +#› %u : The string from the unstagedstr style if there are unstaged changes in the repository. +#› %R : The base directory of the repository. +#› %r : The repository name. If %R is /foo/bar/repoXY, %r is repoXY. +#› %S : A subdirectory within a repository. If $PWD is /foo/bar/repoXY/beer/tasty, %S is beer/tasty. +#› %m : A "misc" replacement. It is at the discretion of the backend to decide what this replacement expands to. + +function +vi-theme-default() { + local vcs_prompt_prefix="%F{magenta}(%F{white}%s%F{magenta})%f" + local vcs_prompt_hyphen="%F{yellow}-%f" + local vcs_prompt_normal="%F{magenta}[%m%c%u%b%F{magenta}]%f" + local vcs_prompt_action="%F{magenta}[%m%c%u%b%F{magenta}|%F{red}%a%F{magenta}]%f" + + OHMYVIA_VCS_PROMPT_NORMAL=${OHMYVIA_VCS_PROMPT_NORMAL:-"$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal"} + OHMYVIA_VCS_PROMPT_ACTION=${OHMYVIA_VCS_PROMPT_ACTION:-"$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_action"} +} + +function +vi-theme-alphabet() { + local vcs_prompt_prefix="%F{magenta}(%F{white}%s%F{magenta})%f" + local vcs_prompt_hyphen="%F{yellow}-%f" + local vcs_prompt_normal="%F{magenta}[%m%c%u%b%F{magenta}]%f" + local vcs_prompt_action="%F{magenta}[%m%c%u%b %F{magenta}| %F{red}%a%F{magenta}]%f" + + OHMYVIA_VCS_PROMPT_NORMAL="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal" + OHMYVIA_VCS_PROMPT_ACTION="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_action" +} + +function +vi-theme-djou() { + local vcs_prompt_prefix="%F{white}%s%f" + local vcs_prompt_hyphen=" %F{yellow}-%f " + local vcs_prompt_normal="%m%c%u%b%f" + local vcs_prompt_action="%m%c%u%b %F{magenta}| %F{red}%a%f" + + OHMYVIA_VCS_PROMPT_NORMAL="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal" + OHMYVIA_VCS_PROMPT_ACTION="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_action" +} + +function +vi-theme-kiwi() { + local vcs_prompt_prefix="%F{magenta}(%F{white}%s%F{magenta})%f" + local vcs_prompt_hyphen="%F{yellow}-%f" + local vcs_prompt_normal="%F{magenta}[%m%c%u%b%F{magenta}]%f" + local vcs_prompt_action="%F{magenta}[%m%c%u%b%F{yellow}|%F{red}%a%F{magenta}]%f" + + OHMYVIA_VCS_PROMPT_NORMAL="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal" + OHMYVIA_VCS_PROMPT_ACTION="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_action" +} + +function +vi-theme-jon() { + local vcs_prompt_prefix="" + local vcs_prompt_hyphen="" + local vcs_prompt_normal="%F{magenta}[%m%c%u%b%F{magenta}]%f" + local vcs_prompt_action="%F{magenta}[%m%c%u%b%F{magenta}|%F{red}%a%F{magenta}]%f" + + OHMYVIA_VCS_PROMPT_NORMAL="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal" + OHMYVIA_VCS_PROMPT_ACTION="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_action" +} + +# vim: ft=zsh fenc=utf-8 + diff --git a/functions/vcs_utils.zsh b/functions/vcs_utils.zsh new file mode 100644 index 0000000000000000000000000000000000000000..192ad55a2c0bb09a5c7332d4ffabf0c888e944ff --- /dev/null +++ b/functions/vcs_utils.zsh @@ -0,0 +1,35 @@ +# +# functions/vcs_utils.zsh - provide supplemental VCS 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. +# + +# Thanks to http://eseth.org/2010/git-in-zsh.html +function +vi-git-stash() { + if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then + hook_com[misc]+=$OHMYVIA_VCS_COLOR_STASH + fi +} + +# Thanks to https://github.com/sunaku/home/ +function +vi-git-untracked() { + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \ + git status --porcelain | fgrep '??' &> /dev/null ; then + # This will show the marker if there are any untracked files in repo. + # If instead you want to show the marker only if there are untracked + # files in $PWD, use: + #[[ -n $(git ls-files --others --exclude-standard) ]] ; then + hook_com[misc]+=$OHMYVIA_VCS_COLOR_UNTRACKED + fi +} + +# Erase hook_com[misc] ( ie. %m ) to avoid dealing with backends info outputs +# Add $vcs_clean_color to setup default %b coloring in vcs prompt +function +vi-misc-init() { + hook_com[misc]=$OHMYVIA_VCS_COLOR_CLEAN +} + +# vim: ft=zsh fenc=utf-8 + diff --git a/via.zsh-theme b/via.zsh-theme index d7e80ed0bb7d49b0a482ef7ffe7698ec03169cca..72caecf233fa0de0c6a686ac65e8f2b8a53448f8 100644 --- a/via.zsh-theme +++ b/via.zsh-theme @@ -1,5 +1,24 @@ +# # VIA ZSH Theme - Preview: ASAP # Fork from the historical VIA Centrale Réseaux ZSH Theme +# +# 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. +# + +################################################################################# +# Source functions +################################################################################# + +OHMYVIA_INSTALLATION_PATH="$(dirname "$0")" + +source $OHMYVIA_INSTALLATION_PATH/functions/vcs_themes.zsh +source $OHMYVIA_INSTALLATION_PATH/functions/vcs_utils.zsh + +################################################################################# +# Setup prompts +################################################################################# local time_format=${OHMYVIA_TIME_FORMAT:-"%D{%H:%M}"} local clock="%B%F{cyan}$time_format%f%b" @@ -30,60 +49,23 @@ 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 -local vcs_unstaged_color=${OHMYVIA_VCS_UNSTAGED_COLOR:-"%F{red}"} -local vcs_staged_color=${OHMYVIA_VCS_STAGED_COLOR:-"%F{yellow}"} -local vcs_untracked_color=${OHMYVIA_VCS_UNTRACKED_COLOR:-"%F{blue}"} -local vcs_stash_color=${OHMYVIA_VCS_STASH_COLOR:-"%F{cyan}"} -local vcs_clean_color=${OHMYVIA_VCS_CLEAN_COLOR:-"%F{green}"} - -zstyle ':vcs_info:*' unstagedstr $vcs_unstaged_color -zstyle ':vcs_info:*' stagedstr $vcs_staged_color - -# Thanks to https://github.com/sunaku/home/ -function +vi-git-untracked() { - if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \ - git status --porcelain | fgrep '??' &> /dev/null ; then - # This will show the marker if there are any untracked files in repo. - # If instead you want to show the marker only if there are untracked - # files in $PWD, use: - #[[ -n $(git ls-files --others --exclude-standard) ]] ; then - hook_com[misc]+=$vcs_untracked_color - fi -} - -# Thanks to http://eseth.org/2010/git-in-zsh.html -function +vi-git-stash() { - if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then - hook_com[misc]+=$vcs_stash_color - fi -} - -# Erase hook_com[misc] ( ie. %m ) to avoid dealing with backends info outputs -# Add $vcs_clean_color to setup default %b coloring in vcs prompt -function +vi-misc-init() { - hook_com[misc]=$vcs_clean_color -} +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}"} + +zstyle ':vcs_info:*' unstagedstr $OHMYVIA_VCS_COLOR_UNSTAGED +zstyle ':vcs_info:*' stagedstr $OHMYVIA_VCS_COLOR_STAGED zstyle ':vcs_info:git*+set-message:*' hooks misc-init git-stash git-untracked -# In normal formats and actionformats the following replacements are done: -# %s : The VCS in use (git, hg, svn, etc.). -# %b : Information about the current branch. -# %a : An identifier that describes the action. Only makes sense in actionformats. -# %i : The current revision number or identifier. For hg the hgrevformat style may be used to customize the output. -# %c : The string from the stagedstr style if there are staged changes in the repository. -# %u : The string from the unstagedstr style if there are unstaged changes in the repository. -# %R : The base directory of the repository. -# %r : The repository name. If %R is /foo/bar/repoXY, %r is repoXY. -# %S : A subdirectory within a repository. If $PWD is /foo/bar/repoXY/beer/tasty, %S is beer/tasty. -# %m : A "misc" replacement. It is at the discretion of the backend to decide what this replacement expands to. -local vcs_formats_prefix="%F{magenta}(%F{white}%s%F{magenta})%f" -local vcs_formats_hyphen="%F{yellow}-%f" -local vcs_formats_normal="%F{magenta}[%m%c%u%b%F{magenta}]%f" -local vcs_formats_action="%F{magenta}[%m%c%u%b%F{magenta}|%F{red}%a%F{magenta}]%f" - -zstyle ':vcs_info:*' formats " $vcs_formats_prefix$vcs_formats_hyphen$vcs_formats_normal" -zstyle ':vcs_info:*' actionformats " $vcs_formats_prefix$vcs_formats_hyphen$vcs_formats_action" +# Load VCS theme +OHMYVIA_VCS_THEME=${OHMYVIA_VCS_THEME:-"default"} +eval +vi-theme-$OHMYVIA_VCS_THEME + +zstyle ':vcs_info:*' formats " $OHMYVIA_VCS_PROMPT_NORMAL" +zstyle ':vcs_info:*' actionformats " $OHMYVIA_VCS_PROMPT_ACTION" precmd () { vcs_info } RPROMPT='${vcs_info_msg_0_}'