monkeypatch for zsh-vi-mode

This commit is contained in:
xenia 2022-09-25 16:57:31 -04:00
parent f353ab4ad1
commit 2134ecdc22
3 changed files with 21 additions and 9 deletions

View File

@ -863,6 +863,9 @@ pub struct Properties {
/// The keymap of fish/zsh/cmd /// The keymap of fish/zsh/cmd
#[clap(short = 'k', long, default_value = "viins")] #[clap(short = 'k', long, default_value = "viins")]
pub keymap: String, pub keymap: String,
// The ZVM_MODE variable in zsh-vi-mode
#[clap(short = 'z', long, default_value = "")]
pub zvm_mode: String,
/// The number of currently running jobs /// The number of currently running jobs
#[clap(short, long, default_value_t, value_parser=parse_jobs)] #[clap(short, long, default_value_t, value_parser=parse_jobs)]
pub jobs: i64, pub jobs: i64,
@ -878,6 +881,7 @@ impl Default for Properties {
logical_path: None, logical_path: None,
cmd_duration: None, cmd_duration: None,
keymap: "viins".to_string(), keymap: "viins".to_string(),
zvm_mode: "".to_string(),
jobs: 0, jobs: 0,
} }
} }

View File

@ -87,6 +87,6 @@ VIRTUAL_ENV_DISABLE_PROMPT=1
setopt promptsubst setopt promptsubst
PROMPT='$('::STARSHIP::' prompt --terminal-width="$COLUMNS" --keymap="${KEYMAP:-}" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="${STARSHIP_DURATION:-}" --jobs="$STARSHIP_JOBS_COUNT")' PROMPT='$('::STARSHIP::' prompt --terminal-width="$COLUMNS" --keymap="${KEYMAP:-}" --zvm-mode="${ZVM_MODE:-}" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="${STARSHIP_DURATION:-}" --jobs="$STARSHIP_JOBS_COUNT")'
RPROMPT='$('::STARSHIP::' prompt --right --terminal-width="$COLUMNS" --keymap="${KEYMAP:-}" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="${STARSHIP_DURATION:-}" --jobs="$STARSHIP_JOBS_COUNT")' RPROMPT='$('::STARSHIP::' prompt --right --terminal-width="$COLUMNS" --keymap="${KEYMAP:-}" --zvm-mode="${ZVM_MODE:-}" --status="$STARSHIP_CMD_STATUS" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --cmd-duration="${STARSHIP_DURATION:-}" --jobs="$STARSHIP_JOBS_COUNT")'
PROMPT2="$(::STARSHIP:: prompt --continuation)" PROMPT2="$(::STARSHIP:: prompt --continuation)"

View File

@ -27,6 +27,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let props = &context.properties; let props = &context.properties;
let exit_code = props.status_code.as_deref().unwrap_or("0"); let exit_code = props.status_code.as_deref().unwrap_or("0");
let keymap = props.keymap.as_str(); let keymap = props.keymap.as_str();
let zvm_mode = props.zvm_mode.as_str();
let exit_success = exit_code == "0"; let exit_success = exit_code == "0";
// Match shell "keymap" names to normalized vi modes // Match shell "keymap" names to normalized vi modes
@ -34,13 +35,20 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
// Unfortunately, this is also the name of the non-vi default mode. // Unfortunately, this is also the name of the non-vi default mode.
// We do some environment detection in src/init.rs to translate. // We do some environment detection in src/init.rs to translate.
// The result: in non-vi fish, keymap is always reported as "insert" // The result: in non-vi fish, keymap is always reported as "insert"
let mode = match (&context.shell, keymap) { let mode = match (&context.shell, zvm_mode, keymap) {
(Shell::Fish, "default") (Shell::Zsh, "n", _) => ShellEditMode::Normal,
| (Shell::Zsh, "vicmd") (Shell::Zsh, "i", _) => ShellEditMode::Insert,
| (Shell::Cmd | Shell::PowerShell | Shell::Pwsh, "vi") => ShellEditMode::Normal, (Shell::Zsh, "v", _) => ShellEditMode::Visual,
(Shell::Fish, "visual") => ShellEditMode::Visual, (Shell::Zsh, "vl", _) => ShellEditMode::Visual,
(Shell::Fish, "replace") => ShellEditMode::Replace, (Shell::Zsh, "r", _) => ShellEditMode::Replace,
(Shell::Fish, "replace_one") => ShellEditMode::ReplaceOne,
(Shell::Fish, _, "default")
| (Shell::Zsh, _, "vicmd")
| (Shell::Cmd | Shell::PowerShell | Shell::Pwsh, _, "vi") => ShellEditMode::Normal,
(Shell::Fish, _, "visual") => ShellEditMode::Visual,
(Shell::Fish, _, "replace") => ShellEditMode::Replace,
(Shell::Fish, _, "replace_one") => ShellEditMode::ReplaceOne,
_ => ASSUMED_MODE, _ => ASSUMED_MODE,
}; };