Adds Murex shell support to init

This commit is contained in:
Jeff Melton 2025-09-06 22:38:01 -05:00
parent 2299f2834b
commit 255419606a
9 changed files with 108 additions and 4 deletions

View File

@ -114,7 +114,7 @@ _arguments "${_arguments_options[@]}" : \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
':shell:(bash elvish fish nushell posix powershell tcsh xonsh zsh)' \
':shell:(bash elvish fish murex nushell posix powershell tcsh xonsh zsh)' \
&& ret=0
;;
(query)

View File

@ -177,7 +177,7 @@ _zoxide() {
return 0
;;
zoxide__init)
opts="-h -V --no-cmd --cmd --hook --help --version bash elvish fish nushell posix powershell tcsh xonsh zsh"
opts="-h -V --no-cmd --cmd --hook --help --version bash elvish fish murex nushell posix powershell tcsh xonsh zsh"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0

View File

@ -57,7 +57,7 @@ module completions {
]
def "nu-complete zoxide init shell" [] {
[ "bash" "elvish" "fish" "nushell" "posix" "powershell" "tcsh" "xonsh" "zsh" ]
[ "bash" "elvish" "fish" "murex" "nushell" "posix" "powershell" "tcsh" "xonsh" "zsh" ]
}
def "nu-complete zoxide init hook" [] {

View File

@ -191,6 +191,7 @@ const completion: Fig.Spec = {
"bash",
"elvish",
"fish",
"murex",
"nushell",
"posix",
"powershell",

View File

@ -27,6 +27,7 @@ in pkgs.mkShell {
pkgs.ksh
pkgs.nushell
pkgs.powershell
pkgs.murex
pkgs.tcsh
pkgs.xonsh
pkgs.zsh

View File

@ -149,6 +149,7 @@ pub enum InitShell {
Bash,
Elvish,
Fish,
Murex,
Nushell,
#[clap(alias = "ksh")]
Posix,

View File

@ -6,7 +6,7 @@ use askama::Template;
use crate::cmd::{Init, InitShell, Run};
use crate::config;
use crate::error::BrokenPipeHandler;
use crate::shell::{Bash, Elvish, Fish, Nushell, Opts, Posix, Powershell, Tcsh, Xonsh, Zsh};
use crate::shell::{Bash, Elvish, Fish, Murex, Nushell, Opts, Posix, Powershell, Tcsh, Xonsh, Zsh};
impl Run for Init {
fn run(&self) -> Result<()> {
@ -19,6 +19,7 @@ impl Run for Init {
InitShell::Bash => Bash(opts).render(),
InitShell::Elvish => Elvish(opts).render(),
InitShell::Fish => Fish(opts).render(),
InitShell::Murex => Murex(opts).render(),
InitShell::Nushell => Nushell(opts).render(),
InitShell::Posix => Posix(opts).render(),
InitShell::Powershell => Powershell(opts).render(),

View File

@ -26,6 +26,7 @@ macro_rules! make_template {
make_template!(Bash, "bash.txt");
make_template!(Elvish, "elvish.txt");
make_template!(Fish, "fish.txt");
make_template!(Murex, "murex.txt");
make_template!(Nushell, "nushell.txt");
make_template!(Posix, "posix.txt");
make_template!(Powershell, "powershell.txt");
@ -249,6 +250,22 @@ mod tests {
.stderr("");
}
#[apply(opts)]
fn murex_murex(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
let opts = Opts { cmd, hook, echo, resolve_symlinks };
let source = Murex(&opts).render().unwrap();
let assert = Command::new("murex")
.args(["-c", &source, "--quiet"])
.assert()
.success()
.stderr("");
if opts.hook != InitHook::Pwd {
assert.stdout("");
}
}
#[apply(opts)]
fn tcsh_tcsh(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
let opts = Opts { cmd, hook, echo, resolve_symlinks };

83
templates/murex.txt Normal file
View File

@ -0,0 +1,83 @@
{%- let section = "# =============================================================================\n#" -%}
{%- let not_configured = "# -- not configured --" -%}
# Code generated by zoxide. DO NOT EDIT.
{{ section }}
# Hook configuration for zoxide.
#
{% match hook %}
{%- when InitHook::None -%}
{{ not_configured }}
{%- when InitHook::Prompt -%}
# Update database after each command completes.
event onPrompt zoxide=command-completion {
zoxide add -- $PWD
}
{%- when InitHook::Pwd -%}
out "zoxide: PWD hooks are not supported on Murex."
out " Use 'zoxide init murex --hook prompt' instead."
{%- endmatch %}
{{ section }}
# When using zoxide with --no-cmd, alias these internal functions as desired.
#
# Jump to a directory using only keywords.
function __zoxide_z {
# No args: go home
if { !$ARGS } {
cd ~
{%- if echo %} out $PWD {%- endif %}
return
}
# Previous dir
if { $ARGS[0] == "-" } {
cd -
{%- if echo %} out $PWD {%- endif %}
return
}
# Query and jump
zoxide query --exclude $PWD -- @PARAMS -> set: str __z
cd $__z
{%- if echo %}
out $PWD
{%- endif %}
}
# Jump to a directory using interactive search.
function __zoxide_zi {
zoxide query --interactive -- @PARAMS -> set: str __z
cd $__z
{%- if echo %}
out $PWD
{%- endif %}
}
{{ section }}
# Commands for zoxide. Disable these using --no-cmd.
#
{%- match cmd %}
{%- when Some with (cmd) %}
function {{cmd}} { __zoxide_z @PARAMS }
function {{cmd}}i { __zoxide_zi @PARAMS }
{%- when None %}
{{ not_configured }}
{%- endmatch %}
{{ section }}
# To initialize zoxide, add this to your Murex profile (~/.murex_profile):
#
# zoxide init murex --hook prompt -> source