summaryrefslogtreecommitdiff
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
parent6bc0b1c04f8e2535648bb791a0a803c15115d2bc (diff)
Add Zsh plugin support with prompt integration
-rw-r--r--.cargo/config.toml4
-rwxr-xr-xscripts/zsh_support/install.sh3
-rw-r--r--scripts/zsh_support/jvcs.plugin.zsh150
-rw-r--r--src/bin/jv.rs25
4 files changed, 174 insertions, 8 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml
index 23ebcc1..e74dd80 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -27,6 +27,10 @@ to = "completions/bash/completion_jv.sh"
from = "scripts/completions/bash/completion_jvv.sh"
to = "completions/bash/completion_jvv.sh"
+[copies.zsh_plugin]
+from = "scripts/zsh_support/jvcs.plugin.zsh"
+to = "scripts/zsh_support/jvcs.plugin.zsh"
+
# Entries
[copies.entry_bash]
from = "scripts/jv_cli.sh"
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
diff --git a/src/bin/jv.rs b/src/bin/jv.rs
index 09e6ece..e31061e 100644
--- a/src/bin/jv.rs
+++ b/src/bin/jv.rs
@@ -1258,33 +1258,42 @@ async fn main() {
}
JustEnoughVcsWorkspaceCommand::GetWorkspaceDir => {
if let Some(local_dir) = current_local_path() {
- println!("{}", local_dir.display())
+ println!("{}", local_dir.display());
+ return;
};
+ exit(1)
}
JustEnoughVcsWorkspaceCommand::GetCurrentAccount => {
let _ = correct_current_dir();
if let Ok(local_config) = LocalConfig::read().await {
if local_config.is_host_mode() {
- println!("host/{}", local_config.current_account())
+ println!("host/{}", local_config.current_account());
+ return;
} else {
- println!("{}", local_config.current_account())
+ println!("{}", local_config.current_account());
+ return;
}
};
+ exit(1)
}
JustEnoughVcsWorkspaceCommand::GetCurrentUpstream => {
let _ = correct_current_dir();
if let Ok(local_config) = LocalConfig::read().await {
- println!("{}", local_config.upstream_addr())
+ println!("{}", local_config.upstream_addr());
+ return;
};
+ exit(1)
}
JustEnoughVcsWorkspaceCommand::GetCurrentSheet => {
let _ = correct_current_dir();
if let Ok(local_config) = LocalConfig::read().await {
- println!(
- "{}",
- local_config.sheet_in_use().clone().unwrap_or_default()
- )
+ let sheet_name = local_config.sheet_in_use().clone().unwrap_or_default();
+ if sheet_name.len() > 0 {
+ println!("{}", sheet_name);
+ return;
+ }
};
+ exit(1)
}
// Debug Tools