summaryrefslogtreecommitdiff
path: root/scripts/zsh_support
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-01-03 22:57:15 +0800
committer魏曹先生 <1992414357@qq.com>2026-01-03 22:57:15 +0800
commit8eda07df4cd8953fbf73a8d3cebd1adcf97d6d2b (patch)
tree17903e4a939f462601afc921dc6c24fb579fa151 /scripts/zsh_support
parent6bc0b1c04f8e2535648bb791a0a803c15115d2bc (diff)
Add Zsh plugin support with prompt integration
Diffstat (limited to 'scripts/zsh_support')
-rwxr-xr-xscripts/zsh_support/install.sh3
-rw-r--r--scripts/zsh_support/jvcs.plugin.zsh150
2 files changed, 153 insertions, 0 deletions
diff --git a/scripts/zsh_support/install.sh b/scripts/zsh_support/install.sh
new file mode 100755
index 0000000..aa92952
--- /dev/null
+++ b/scripts/zsh_support/install.sh
@@ -0,0 +1,3 @@
+#!/bin/zsh
+cd "$(dirname "$0")"
+cp jvcs.plugin.zsh ~/.oh-my-zsh/custom/plugins/jvcs/jvcs.plugin.zsh
diff --git a/scripts/zsh_support/jvcs.plugin.zsh b/scripts/zsh_support/jvcs.plugin.zsh
new file mode 100644
index 0000000..19dc24f
--- /dev/null
+++ b/scripts/zsh_support/jvcs.plugin.zsh
@@ -0,0 +1,150 @@
+# ████████ ████████
+# ██▒▒▒▒▒▒▒▒██ ██▒▒▒▒▒▒▒▒██
+# ██ ▒▒██ ██▒▒ ██ █████ ██ ██ ██████ █████
+# ██ ▒▒████████▒▒ ██ ▒▒▒██ ██ ██ ██████ ██████
+# ██ ▒▒▒▒▒▒▒▒ ██ ██ ██ ██ ███▒▒▒█ █▒▒▒▒█
+# ██ ██ ██ ██ ██ ███ ▒ ████ ▒
+# ██ ██ ██ ██ ██ ███ ▒████
+# ██ ████ ████ ██ ██ ▒██ ██▒ ███ ▒▒▒██
+# ██ ████ ████ ██ █ ██ ██ ██ ███ █ ██ ██
+# ██ ████ ████ ██ █ ██ ▒████▒ ▒██████ ██████
+# ██ ▒▒▒▒ ▒▒▒▒ █ ██ ▒████ ▒██▒ ██████ ▒████▒
+# ██ ██ ██ ▒▒▒▒ ▒▒ ▒▒▒▒▒▒ ▒▒▒▒
+# ██ ██████████ ██
+# ██ ██ JustEnoughVCS CommandLine
+# ████████████████████████████████ Zsh Plugin
+# ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
+
+autoload -Uz add-zsh-hook
+
+#####################
+### CONFIGURATION ###
+#####################
+
+# DISPLAY_LEVEL
+# FULL = 127.0.0.1:25331/account/sheet
+# NORMAL = account/sheet
+# SHORT = sheet
+JVCS_VIEW='NORMAL'
+
+###################
+### THEME READS ###
+###################
+
+JVCS_PROMPT_SEGMENT=''
+
+######################
+### INTERNAL STATE ###
+######################
+
+JVCS_DISPLAY=''
+JVCS_WS=''
+JVCS_ACCOUNT=''
+JVCS_SHEET=''
+JVCS_UPSTREAM=''
+
+###################
+### STATE LAYER ###
+###################
+
+jvcs_read_state() {
+ JVCS_WS="$(jv _workspace_dir)"
+ JVCS_ACCOUNT="$(jv _account)"
+ JVCS_SHEET="$(jv _sheet)"
+ JVCS_UPSTREAM="$(jv _upstream)"
+}
+
+##################
+### VIEW LAYER ###
+##################
+
+jvcs_compute_view() {
+ # Must be in a Workspace, otherwise do not display
+ if [[ -z "$JVCS_WS" ]]; then
+ JVCS_DISPLAY=''
+ return
+ fi
+ JVCS_DISPLAY='1'
+}
+
+####################
+### RENDER LAYER ###
+####################
+
+jvcs_render_prompt() {
+ # Only set prompt segment if display is enabled
+ if [[ -n "$JVCS_DISPLAY" ]]; then
+ case "$JVCS_VIEW" in
+ FULL)
+ JVCS_PROMPT_SEGMENT="%{$fg[white]%}${JVCS_UPSTREAM}/${JVCS_ACCOUNT}/${JVCS_SHEET} > %{$reset_color%}"
+ ;;
+ NORMAL)
+ JVCS_PROMPT_SEGMENT="%{$fg[white]%}${JVCS_ACCOUNT}/${JVCS_SHEET} > %{$reset_color%}"
+ ;;
+ SHORT)
+ JVCS_PROMPT_SEGMENT="%{$fg[white]%}${JVCS_SHEET} > %{$reset_color%}"
+ ;;
+ *)
+ JVCS_PROMPT_SEGMENT=''
+ ;;
+ esac
+ else
+ JVCS_PROMPT_SEGMENT=''
+ fi
+}
+
+####################
+### ORCHESTRATOR ###
+####################
+
+jvcs_update() {
+ jvcs_read_state
+ jvcs_compute_view
+ jvcs_render_prompt
+}
+
+#############
+### HOOKS ###
+#############
+
+JVCS_NEED_REFRESH=0
+
+jvcs_preexec() {
+ case "$1" in
+ jv\ status | \
+ jv\ use* | \
+ jv\ as* | \
+ jv\ exit | \
+ jv\ sheet\ use* | \
+ jv\ sheet\ sheet\ exit | \
+ jv\ account\ as*)
+ JVCS_NEED_REFRESH=1
+ ;;
+ esac
+}
+
+jvcs_precmd() {
+ [[ "$JVCS_NEED_REFRESH" -eq 1 ]] || return
+ JVCS_NEED_REFRESH=0
+ jvcs_update
+}
+
+jvcs_chpwd() {
+ jvcs_update
+}
+
+add-zsh-hook preexec jvcs_preexec
+add-zsh-hook precmd jvcs_precmd
+add-zsh-hook chpwd jvcs_chpwd
+
+###############################
+### FALLBACK INITIALIZATION ###
+###############################
+
+jvcs_precmd_init() {
+ [[ -n "${JVCS_INITIALIZED:-}" ]] && return
+ JVCS_INITIALIZED=1
+ jvcs_update
+}
+
+add-zsh-hook precmd jvcs_precmd_init