diff options
author | Robby Russell <robby@planetargon.com> | 2016-05-18 19:17:31 -0700 |
---|---|---|
committer | Robby Russell <robby@planetargon.com> | 2016-05-18 19:17:31 -0700 |
commit | 23ed432d3566c789d9c59ccbf8d16ec68db66c74 (patch) | |
tree | 9111de6fe648776713ad45f3d689bfaef3bd0843 /plugins/fossil/fossil.plugin.zsh | |
parent | de427f32b3cfce3a865ee69aaf1bfe41e9952f51 (diff) | |
parent | 2bce3b1f588ef2a5245e7a3f4b1693c2c07d1dbc (diff) | |
download | zsh-23ed432d3566c789d9c59ccbf8d16ec68db66c74.tar.gz zsh-23ed432d3566c789d9c59ccbf8d16ec68db66c74.tar.bz2 zsh-23ed432d3566c789d9c59ccbf8d16ec68db66c74.zip |
Merge pull request #5077 from jgmdev/master
Added fossil plugin.
Diffstat (limited to 'plugins/fossil/fossil.plugin.zsh')
-rw-r--r-- | plugins/fossil/fossil.plugin.zsh | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/plugins/fossil/fossil.plugin.zsh b/plugins/fossil/fossil.plugin.zsh new file mode 100644 index 000000000..1ae166e62 --- /dev/null +++ b/plugins/fossil/fossil.plugin.zsh @@ -0,0 +1,89 @@ +_FOSSIL_PROMPT="" + +# Prefix at the very beginning of the prompt, before the branch name +ZSH_THEME_FOSSIL_PROMPT_PREFIX="%{$fg_bold[blue]%}fossil:(%{$fg_bold[red]%}" + +# At the very end of the prompt +ZSH_THEME_FOSSIL_PROMPT_SUFFIX="%{$fg_bold[blue]%})" + +# Text to display if the branch is dirty +ZSH_THEME_FOSSIL_PROMPT_DIRTY=" %{$fg_bold[red]%}✖" + +# Text to display if the branch is clean +ZSH_THEME_FOSSIL_PROMPT_CLEAN=" %{$fg_bold[green]%}✔" + +function fossil_prompt_info () { + local _OUTPUT=`fossil branch 2>&1` + local _STATUS=`echo $_OUTPUT | grep "use --repo"` + if [ "$_STATUS" = "" ]; then + local _EDITED=`fossil changes` + local _EDITED_SYM="$ZSH_THEME_FOSSIL_PROMPT_CLEAN" + local _BRANCH=`echo $_OUTPUT | grep "* " | sed 's/* //g'` + + if [ "$_EDITED" != "" ]; then + _EDITED_SYM="$ZSH_THEME_FOSSIL_PROMPT_DIRTY" + fi + + echo "$ZSH_THEME_FOSSIL_PROMPT_PREFIX" \ + "$_BRANCH" \ + "$ZSH_THEME_FOSSIL_PROMPT_SUFFIX" \ + "$_EDITED_SYM"\ + "%{$reset_color%}" + fi +} + +function _fossil_get_command_list () { + fossil help -a | grep -v "Usage|Common|This is" +} + +function _fossil () { + local context state state_descr line + typeset -A opt_args + + _arguments \ + '1: :->command'\ + '2: :->subcommand' + + case $state in + command) + local _OUTPUT=`fossil branch 2>&1 | grep "use --repo"` + if [ "$_OUTPUT" = "" ]; then + compadd `_fossil_get_command_list` + else + compadd clone init import help version + fi + ;; + subcommand) + if [ "$words[2]" = "help" ]; then + compadd `_fossil_get_command_list` + else + compcall -D + fi + ;; + esac +} + +function _fossil_prompt () { + local current=`echo $PROMPT $RPROMPT | grep fossil` + + if [ "$_FOSSIL_PROMPT" = "" -o "$current" = "" ]; then + local _prompt=${PROMPT} + local _rprompt=${RPROMPT} + + local is_prompt=`echo $PROMPT | grep git` + + if [ "$is_prompt" = "" ]; then + export RPROMPT="$_rprompt"'$(fossil_prompt_info)' + else + export PROMPT="$_prompt"'$(fossil_prompt_info) ' + fi + + _FOSSIL_PROMPT="1" + fi +} + +compdef _fossil fossil + +autoload -U add-zsh-hook + +add-zsh-hook precmd _fossil_prompt |