summaryrefslogtreecommitdiffstats
path: root/zsh/oh-my-zsh/plugins/fossil
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-10-03 21:42:20 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-10-03 21:42:20 +0530
commitaf120ab348f2e1a5a39dec035ed9dcf84189a64e (patch)
tree2a3aadd7ce1b7b771dfe3fe7c983569726c8d7ed /zsh/oh-my-zsh/plugins/fossil
downloaddotfiles-af120ab348f2e1a5a39dec035ed9dcf84189a64e.tar.gz
dotfiles-af120ab348f2e1a5a39dec035ed9dcf84189a64e.tar.bz2
dotfiles-af120ab348f2e1a5a39dec035ed9dcf84189a64e.zip
dotfiles
Diffstat (limited to 'zsh/oh-my-zsh/plugins/fossil')
-rw-r--r--zsh/oh-my-zsh/plugins/fossil/README.md7
-rw-r--r--zsh/oh-my-zsh/plugins/fossil/_fossil32
-rw-r--r--zsh/oh-my-zsh/plugins/fossil/fossil.plugin.zsh57
3 files changed, 96 insertions, 0 deletions
diff --git a/zsh/oh-my-zsh/plugins/fossil/README.md b/zsh/oh-my-zsh/plugins/fossil/README.md
new file mode 100644
index 0000000..5bb47b7
--- /dev/null
+++ b/zsh/oh-my-zsh/plugins/fossil/README.md
@@ -0,0 +1,7 @@
+## Fossil Plugin
+
+This plugin adds completion support and prompt for fossil repositories.
+The prompt will display the current branch and status been dirty or clean.
+
+### CONTRIBUTOR
+ - Jefferson González ([jgmdev](https://github.com/jgmdev))
diff --git a/zsh/oh-my-zsh/plugins/fossil/_fossil b/zsh/oh-my-zsh/plugins/fossil/_fossil
new file mode 100644
index 0000000..d2d48bd
--- /dev/null
+++ b/zsh/oh-my-zsh/plugins/fossil/_fossil
@@ -0,0 +1,32 @@
+#compdef fossil
+
+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 [[ -z "$_OUTPUT" ]]; then
+ compadd "$(_fossil_get_command_list)"
+ else
+ compadd clone init import help version
+ fi ;;
+ subcommand)
+ case "$words[2]" in
+ help) compadd "$(_fossil_get_command_list)" ;;
+ add) compadd "$(fossil extra)" ;;
+ *) compcall -D ;;
+ esac ;;
+ esac
+}
+
+_fossil "$@"
diff --git a/zsh/oh-my-zsh/plugins/fossil/fossil.plugin.zsh b/zsh/oh-my-zsh/plugins/fossil/fossil.plugin.zsh
new file mode 100644
index 0000000..a2123f4
--- /dev/null
+++ b/zsh/oh-my-zsh/plugins/fossil/fossil.plugin.zsh
@@ -0,0 +1,57 @@
+_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 info=$(fossil branch 2>&1)
+
+ # if we're not in a fossil repo, don't show anything
+ ! command grep -q "use --repo" <<< "$info" || return
+
+ local branch=$(echo $info | grep "* " | sed 's/* //g')
+ local changes=$(fossil changes)
+ local dirty="$ZSH_THEME_FOSSIL_PROMPT_CLEAN"
+
+ if [[ -n "$changes" ]]; then
+ dirty="$ZSH_THEME_FOSSIL_PROMPT_DIRTY"
+ fi
+
+ printf '%s %s %s %s %s' \
+ "$ZSH_THEME_FOSSIL_PROMPT_PREFIX" \
+ "${branch:gs/%/%%}" \
+ "$ZSH_THEME_FOSSIL_PROMPT_SUFFIX" \
+ "$dirty" \
+ "%{$reset_color%}"
+}
+
+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
+ RPROMPT="$_rprompt"'$(fossil_prompt_info)'
+ else
+ PROMPT="$_prompt"'$(fossil_prompt_info) '
+ fi
+
+ _FOSSIL_PROMPT="1"
+ fi
+}
+
+autoload -U add-zsh-hook
+add-zsh-hook precmd _fossil_prompt