diff --git a/README.md b/README.md index e52ad6c90504775e2f1c43d46776fa8266fbeb42..0ba107ccd95f62932b367eded96b417bfb11d092 100644 --- a/README.md +++ b/README.md @@ -1,77 +1,56 @@ -VIA theme for ZSH -================= +# ViaRézo ZSH Theme [](http://www.wtfpl.net) -This is a theme for ZSH which mainly forks the historical theme used on -[VIA Centrale Réseaux](https://via.ecp.fr/) servers. It can be used with -ZSH frameworks such as [Oh-My-ZSH](https://github.com/robbyrussell/oh-my-zsh). +This is a theme for ZSH which mainly forks the historical theme used on VIA Centrale Réseaux servers. It can be used with ZSH frameworks such as [Oh-My-ZSH](https://github.com/robbyrussell/oh-my-zsh).  -Testing -------- +## VCS caption -See on [Docker Hub](https://hub.docker.com/r/badouralix/oh-my-via/) for a testing image. +| Color | State | Variable | +|:------:|:--------------------------:|:---------------------------------:| +| red | there are unstaged files | `OHMYVIAREZO_VCS_COLOR_UNSTAGED` | +| yellow | there are staged files | `OHMYVIAREZO_VCS_COLOR_STAGED` | +| blue | there are untracked files | `OHMYVIAREZO_VCS_COLOR_UNTRACKED` | +| cyan | stash stack is not empty | `OHMYVIAREZO_VCS_COLOR_STASH` | +| green | working directory is clean | `OHMYVIAREZO_VCS_COLOR_CLEAN` | -Info ----- +## Install for Oh-My-ZSH -### VCS caption - -| Color | State | Variable | -|:------:|:--------------------------:|:-----------------------------:| -| 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 ------ - -### Install for Oh-My-ZSH - -In order to use this theme, you have to clone this repository in your Oh-My-ZSH -`custom/themes` directory ( usually `~/.oh-my-zsh/custom/themes` ) : +In order to use this theme, you have to clone this repository in your Oh-My-ZSH `custom/themes` directory (usually `~/.oh-my-zsh/custom/themes`): -``` -git clone https://github.com/badouralix/oh-my-via.git $ZSH/custom/themes/oh-my-via +```shell +git clone https://gitlab.viarezo.fr/ViaRezo/oh-my-viarezo.git $ZSH/custom/themes/oh-my-viarezo ``` You then need to select this theme in your `~/.zshrc` : -``` -ZSH_THEME="oh-my-via/via" +```shell +ZSH_THEME="oh-my-viarezo/viarezo" ``` -### Customization +## Customization -Time format defaults to `%D{%H:%M}`, but can be overwritten by setting the variable -`OHMYVIA_TIME_FORMAT` in your `~/.zshrc`. +Time format defaults to `%D{%H:%M}`, but can be overwritten by setting the variable `OHMYVIAREZO_TIME_FORMAT` in your `~/.zshrc`. -Hostname may be printed up to the first `.` or hidden with the variable -`OHMYVIA_CONTEXT_HOSTNAME`. +Hostname may be printed up to the first `.` or hidden with the variable `OHMYVIAREZO_CONTEXT_HOSTNAME`. -VCS theme can be set through the variable `OHMYVIA_VCS_THEME`. +VCS theme can be set through the variable `OHMYVIAREZO_VCS_THEME`. -Unit testing ------------- +## Unit testing Oh-My-VIA uses [ZUnit](https://github.com/molovo/zunit) as unit testing framework. To run the tests, just run: -``` +```shell zunit test ``` - -License -------- +## License Unless explicitly stated to the contrary, all contents licensed under the [WTFPL](LICENSE). diff --git a/functions/prompt_utils.zsh b/functions/prompt_utils.zsh index b9177f612e6dfdf0f2de09094e1336c601878738..223977a8a9b76db904f0818e5f9b3313e58d0bd1 100644 --- a/functions/prompt_utils.zsh +++ b/functions/prompt_utils.zsh @@ -9,24 +9,24 @@ # Context: user@hostname (who am I and where am I) # See https://github.com/bhilburn/powerlevel9k/blob/1ff9da64d974265ce2f22bd1da4a47d0b8f7ca90/powerlevel9k.zsh-theme#L434 prompt_context () { - local username="%(!.$OHMYVIA_CONTEXT_ROOT_COLOR.$OHMYVIA_CONTEXT_USER_COLOR)%n%b%f" + local username="%(!.$OHMYVIAREZO_CONTEXT_ROOT_COLOR.$OHMYVIAREZO_CONTEXT_USER_COLOR)%n%b%f" - # Return only username if $OHMYVIA_CONTEXT_HOSTNAME is empty. - if [[ $OHMYVIA_CONTEXT_HOSTNAME == "empty" ]]; then + # Return only username if $OHMYVIAREZO_CONTEXT_HOSTNAME is empty. + if [[ $OHMYVIAREZO_CONTEXT_HOSTNAME == "empty" ]]; then echo "${username}" return fi - local separator="$OHMYVIA_CONTEXT_SEPARATOR_COLOR@%b%f" + local separator="$OHMYVIAREZO_CONTEXT_SEPARATOR_COLOR@%b%f" # Handle hostnames containing `.` (defaults to full machine hostname prompt.) - local colorless_hostname="$OHMYVIA_CONTEXT_HOSTNAME" - if [[ $OHMYVIA_CONTEXT_HOSTNAME == 'full' ]]; then + local colorless_hostname="$OHMYVIAREZO_CONTEXT_HOSTNAME" + if [[ $OHMYVIAREZO_CONTEXT_HOSTNAME == 'full' ]]; then colorless_hostname="%M" - elif [[ $OHMYVIA_CONTEXT_HOSTNAME == 'partial' ]]; then + elif [[ $OHMYVIAREZO_CONTEXT_HOSTNAME == 'partial' ]]; then colorless_hostname="%m" fi - local hostname="$OHMYVIA_CONTEXT_HOSTNAME_COLOR${colorless_hostname}%b%f" + local hostname="$OHMYVIAREZO_CONTEXT_HOSTNAME_COLOR${colorless_hostname}%b%f" echo "${username}${separator}${hostname}" } @@ -34,17 +34,16 @@ prompt_context () { # Print current directory with ~ instead of $HOME # See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Shell-state prompt_dir () { - local current_dir="$OHMYVIA_DIR_COLOR%~%b%f" + local current_dir="$OHMYVIAREZO_DIR_COLOR%~%b%f" echo $current_dir } # Print current time prompt_time () { - local clock="$OHMYVIA_TIME_COLOR$OHMYVIA_TIME_FORMAT%b%f" + local clock="$OHMYVIAREZO_TIME_COLOR$OHMYVIAREZO_TIME_FORMAT%b%f" echo $clock } # vim: ft=zsh fenc=utf-8 - diff --git a/functions/vcs_themes.zsh b/functions/vcs_themes.zsh index be2d3ab21c6a4c04d874fdbf8e956652f4b4d201..ed193fb7144f84835c3aa355a6fa25de577fde75 100644 --- a/functions/vcs_themes.zsh +++ b/functions/vcs_themes.zsh @@ -24,8 +24,8 @@ 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"} + OHMYVIAREZO_VCS_PROMPT_NORMAL=${OHMYVIAREZO_VCS_PROMPT_NORMAL:-"$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal"} + OHMYVIAREZO_VCS_PROMPT_ACTION=${OHMYVIAREZO_VCS_PROMPT_ACTION:-"$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_action"} } +vi-theme-alphabet () { @@ -34,8 +34,8 @@ 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" + OHMYVIAREZO_VCS_PROMPT_NORMAL="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal" + OHMYVIAREZO_VCS_PROMPT_ACTION="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_action" } +vi-theme-djou () { @@ -44,8 +44,8 @@ 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" + OHMYVIAREZO_VCS_PROMPT_NORMAL="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal" + OHMYVIAREZO_VCS_PROMPT_ACTION="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_action" } +vi-theme-kiwi () { @@ -54,8 +54,8 @@ 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" + OHMYVIAREZO_VCS_PROMPT_NORMAL="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal" + OHMYVIAREZO_VCS_PROMPT_ACTION="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_action" } +vi-theme-jon () { @@ -64,9 +64,8 @@ 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" + OHMYVIAREZO_VCS_PROMPT_NORMAL="$vcs_prompt_prefix$vcs_prompt_hyphen$vcs_prompt_normal" + OHMYVIAREZO_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 index fec582b2332d558488777570d7a6c86a4c46c675..9dfce6d5961482bfdb27e4572b9b08ff7fdf2be6 100644 --- a/functions/vcs_utils.zsh +++ b/functions/vcs_utils.zsh @@ -9,7 +9,7 @@ # Thanks to http://eseth.org/2010/git-in-zsh.html +vi-git-stash () { if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then - hook_com[misc]+=$OHMYVIA_VCS_COLOR_STASH + hook_com[misc]+=$OHMYVIAREZO_VCS_COLOR_STASH fi } @@ -21,15 +21,14 @@ # 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 + hook_com[misc]+=$OHMYVIAREZO_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 +vi-misc-init () { - hook_com[misc]=$OHMYVIA_VCS_COLOR_CLEAN + hook_com[misc]=$OHMYVIAREZO_VCS_COLOR_CLEAN } # vim: ft=zsh fenc=utf-8 - diff --git a/via.zsh-theme b/via.zsh-theme deleted file mode 100644 index 564ae84f21cb95520b8606992f6908239f7dd7d7..0000000000000000000000000000000000000000 --- a/via.zsh-theme +++ /dev/null @@ -1,82 +0,0 @@ -# -# Oh-My-VIA ZSH Theme -# 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/prompt_utils.zsh -source $OHMYVIA_INSTALLATION_PATH/functions/utils.zsh -source $OHMYVIA_INSTALLATION_PATH/functions/vcs_themes.zsh -source $OHMYVIA_INSTALLATION_PATH/functions/vcs_utils.zsh - -################################################################################# -# Variables initialization -################################################################################# - -## Properties - -set_default OHMYVIA_CONTEXT_HOSTNAME "full" -set_default OHMYVIA_CONTEXT_HOSTNAME_COLOR "%B%F{white}" -set_default OHMYVIA_CONTEXT_SEPARATOR_COLOR "%B%F{yellow}" -set_default OHMYVIA_CONTEXT_ROOT_COLOR "%B%F{blue}" -set_default OHMYVIA_CONTEXT_USER_COLOR "%B%F{red}" - -set_default OHMYVIA_DIR_COLOR "%B%F{green}" - -set_default OHMYVIA_STATUS_OK_COLOR "%B%F{yellow}" -set_default OHMYVIA_STATUS_ERROR_COLOR "%B%F{red}" - -set_default OHMYVIA_TIME_COLOR "%B%F{cyan}" -set_default OHMYVIA_TIME_FORMAT "%D{%H:%M}" - -set_default OHMYVIA_VCS_COLOR_UNSTAGED "red" -set_default OHMYVIA_VCS_COLOR_STAGE "yellow" -set_default OHMYVIA_VCS_COLOR_UNTRACKED "blue" -set_default OHMYVIA_VCS_COLOR_STASH "cyan" -set_default OHMYVIA_VCS_COLOR_CLEAN "green" -set_default OHMYVIA_VCS_THEME "default" - - -################################################################################# -# Build left & right prompts -################################################################################# - -OHMYVIA_EOL="%(?.$OHMYVIA_STATUS_OK_COLOR.$OHMYVIA_STATUS_ERROR_COLOR)%#%f%b" - -PROMPT="$(prompt_time) $(prompt_context) $(prompt_dir)${OHMYVIA_EOL} " - -# Display vcs info -# http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Version-Control-Information -autoload -Uz vcs_info - -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 - -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 - -# Load VCS theme -eval +vi-theme-$OHMYVIA_VCS_THEME - -zstyle ':vcs_info:*' formats " $OHMYVIA_VCS_PROMPT_NORMAL" -zstyle ':vcs_info:*' actionformats " $OHMYVIA_VCS_PROMPT_ACTION" - -# Override precmd to update vcs_info_msg_0_ before prompt. -# See http://zsh.sourceforge.net/Doc/Release/Functions.html#Hook-Functions -precmd () { vcs_info } -RPROMPT='${vcs_info_msg_0_}' - -# vim: ft=zsh fenc=utf-8 - diff --git a/viarezo.zsh-theme b/viarezo.zsh-theme new file mode 100644 index 0000000000000000000000000000000000000000..db04d3fbc93b6fbd7dba9256bd7ca831106df9ee --- /dev/null +++ b/viarezo.zsh-theme @@ -0,0 +1,81 @@ +# +# Oh-My-ViaRézo ZSH Theme +# 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 $OHMYVIAREZO_INSTALLATION_PATH/functions/prompt_utils.zsh +source $OHMYVIAREZO_INSTALLATION_PATH/functions/utils.zsh +source $OHMYVIAREZO_INSTALLATION_PATH/functions/vcs_themes.zsh +source $OHMYVIAREZO_INSTALLATION_PATH/functions/vcs_utils.zsh + +################################################################################# +# Variables initialization +################################################################################# + +## Properties + +set_default OHMYVIAREZO_CONTEXT_HOSTNAME "full" +set_default OHMYVIAREZO_CONTEXT_HOSTNAME_COLOR "%B%F{white}" +set_default OHMYVIAREZO_CONTEXT_SEPARATOR_COLOR "%B%F{yellow}" +set_default OHMYVIAREZO_CONTEXT_ROOT_COLOR "%B%F{blue}" +set_default OHMYVIAREZO_CONTEXT_USER_COLOR "%B%F{red}" + +set_default OHMYVIAREZO_DIR_COLOR "%B%F{green}" + +set_default OHMYVIAREZO_STATUS_OK_COLOR "%B%F{yellow}" +set_default OHMYVIAREZO_STATUS_ERROR_COLOR "%B%F{red}" + +set_default OHMYVIAREZO_TIME_COLOR "%B%F{cyan}" +set_default OHMYVIAREZO_TIME_FORMAT "%D{%H:%M}" + +set_default OHMYVIAREZO_VCS_COLOR_UNSTAGED "red" +set_default OHMYVIAREZO_VCS_COLOR_STAGE "yellow" +set_default OHMYVIAREZO_VCS_COLOR_UNTRACKED "blue" +set_default OHMYVIAREZO_VCS_COLOR_STASH "cyan" +set_default OHMYVIAREZO_VCS_COLOR_CLEAN "green" +set_default OHMYVIAREZO_VCS_THEME "default" + + +################################################################################# +# Build left & right prompts +################################################################################# + +OHMYVIAREZO_EOL="%(?.$OHMYVIAREZO_STATUS_OK_COLOR.$OHMYVIAREZO_STATUS_ERROR_COLOR)%#%f%b" + +PROMPT="$(prompt_time) $(prompt_context) $(prompt_dir)${OHMYVIAREZO_EOL} " + +# Display vcs info +# http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Version-Control-Information +autoload -Uz vcs_info + +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 + +zstyle ':vcs_info:*' unstagedstr $OHMYVIAREZO_VCS_COLOR_UNSTAGED +zstyle ':vcs_info:*' stagedstr $OHMYVIAREZO_VCS_COLOR_STAGED + +zstyle ':vcs_info:git*+set-message:*' hooks misc-init git-stash git-untracked + +# Load VCS theme +eval +vi-theme-$OHMYVIAREZO_VCS_THEME + +zstyle ':vcs_info:*' formats " $OHMYVIAREZO_VCS_PROMPT_NORMAL" +zstyle ':vcs_info:*' actionformats " $OHMYVIAREZO_VCS_PROMPT_ACTION" + +# Override precmd to update vcs_info_msg_0_ before prompt. +# See http://zsh.sourceforge.net/Doc/Release/Functions.html#Hook-Functions +precmd () { vcs_info } +RPROMPT='${vcs_info_msg_0_}' + +# vim: ft=zsh fenc=utf-8