summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-12-08 20:11:22 +0800
committer魏曹先生 <1992414357@qq.com>2025-12-08 20:11:22 +0800
commit37e991b7eb1f57090b98ebc02a7fad6a4971e876 (patch)
tree53e4c1dca9de146dc1806c654601667e4dced0d1
parentf87dc291140ccb63919ab20f56c4f86f6df38dde (diff)
Add jvii binary and set default text editor
- Add jvii as a new binary target in Cargo configuration - Set JV_TEXT_EDITOR environment variable to "nano" in CLI scripts - Implement jvii binary with version command support - Add get_default_editor() utility that checks JV_TEXT_EDITOR, EDITOR, then defaults to "jvii"
-rw-r--r--.cargo/config.toml3
-rw-r--r--scripts/jv_cli.ps14
-rw-r--r--scripts/jv_cli.sh4
-rw-r--r--src/bin/jvii.rs19
-rw-r--r--src/utils/env.rs20
-rw-r--r--src/utils/input.rs4
6 files changed, 53 insertions, 1 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml
index 9ba89a6..23ebcc1 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -9,6 +9,9 @@ binaries = [
"jvv",
"jvv.exe",
+
+ "jvii",
+ "jvii.exe"
]
############
diff --git a/scripts/jv_cli.ps1 b/scripts/jv_cli.ps1
index e8d3674..123e28d 100644
--- a/scripts/jv_cli.ps1
+++ b/scripts/jv_cli.ps1
@@ -13,6 +13,10 @@ $SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Next `jv` command will auto-run `jv update`
$env:JV_AUTO_UPDATE = "yes"
+# Use JV_TEXT_EDITOR to set text editor for `jv track --work` `jv align --work`
+# DEFAULT: $EDITOR environment variable, falling back to "jvii" if not set
+$env:JV_TEXT_EDITOR = "nano"
+
###############
### ALIASES ###
###############
diff --git a/scripts/jv_cli.sh b/scripts/jv_cli.sh
index 1e382d7..eb7699a 100644
--- a/scripts/jv_cli.sh
+++ b/scripts/jv_cli.sh
@@ -14,6 +14,10 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Next `jv` command will auto-run `jv update`
export JV_AUTO_UPDATE=yes
+# Use JV_TEXT_EDITOR to set text editor for `jv track --work` `jv align --work`
+# DEFAULT: $EDITOR environment variable, falling back to "jvii" if not set
+export JV_TEXT_EDITOR=nano
+
###############
### ALIASES ###
###############
diff --git a/src/bin/jvii.rs b/src/bin/jvii.rs
new file mode 100644
index 0000000..e7a20bb
--- /dev/null
+++ b/src/bin/jvii.rs
@@ -0,0 +1,19 @@
+#[derive(Parser, Debug)]
+#[command(
+ disable_help_flag = true,
+ disable_version_flag = true,
+ disable_help_subcommand = true,
+ help_template = "{all-args}"
+)]
+
+struct JustEnoughVcsInputer {
+ #[command(subcommand)]
+ command: JustEnoughVcsInputerCommand,
+}
+
+#[derive(Subcommand, Debug)]
+enum JustEnoughVcsInputerCommand {
+ /// Version information
+ #[command(alias = "--version", alias = "-v")]
+ Version(VersionArgs),
+}
diff --git a/src/utils/env.rs b/src/utils/env.rs
index 5a37365..c96760b 100644
--- a/src/utils/env.rs
+++ b/src/utils/env.rs
@@ -47,3 +47,23 @@ pub fn enable_auto_update() -> bool {
}
false
}
+
+/// Gets the default text editor based on environment variables.
+///
+/// The function checks the JV_TEXT_EDITOR and EDITOR environment variables
+/// and returns their values if they are set. If neither variable is set,
+/// it returns "jvii" as the default editor.
+///
+/// # Returns
+/// A String containing the default text editor
+pub async fn get_default_editor() -> String {
+ if let Ok(editor) = std::env::var("JV_TEXT_EDITOR") {
+ return editor;
+ }
+
+ if let Ok(editor) = std::env::var("EDITOR") {
+ return editor;
+ }
+
+ "jvii".to_string()
+}
diff --git a/src/utils/input.rs b/src/utils/input.rs
index 219fe1b..1edcc5d 100644
--- a/src/utils/input.rs
+++ b/src/utils/input.rs
@@ -1,5 +1,7 @@
use tokio::{fs, process::Command};
+use crate::utils::env::get_default_editor;
+
/// Confirm the current operation
/// Waits for user input of 'y' or 'n'
pub async fn confirm_hint(text: impl Into<String>) -> bool {
@@ -69,7 +71,7 @@ pub async fn input_with_editor(
fs::write(cache_path, default_content).await?;
// Get editor from environment variable
- let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vi".to_string());
+ let editor = get_default_editor().await;
// Open editor with cache file
let status = Command::new(editor).arg(cache_path).status().await?;