Compare commits

...

8 Commits

Author SHA1 Message Date
Jeff Melton e2401e9301
Merge 0f8583540f into 194f8e31e4 2025-10-06 08:37:21 -05:00
Ajeet D'Souza 194f8e31e4
Update README.md 2025-10-03 02:59:45 +05:30
Jeff Melton 0f8583540f fixing variable scoping issue 2025-09-08 10:42:07 -05:00
Jeff Melton 7ab8293fc9 fixes flaw in implementation; adds additional test coverage 2025-09-07 12:24:12 -05:00
Jeff Melton e891fc9942 implements feedback from maintainer
- PWD hook
- no-argument `z` goes HOME
- empty query results no longer throw a stack trace
2025-09-07 10:41:03 -05:00
Ajeet D'Souza 918595bca8 typo 2025-09-07 11:23:39 +05:30
Ajeet D'Souza 11362b0c97 Bugfixes + consistency 2025-09-07 11:05:54 +05:30
Jeff Melton 255419606a Adds Murex shell support to init 2025-09-06 22:38:01 -05:00
10 changed files with 162 additions and 5 deletions

View File

@ -12,7 +12,7 @@
<sup>Special thanks to:</sup>
<!-- markdownlint-disable-next-line MD013 -->
<div><img alt="Sponsored by Warp" width="230" src="https://raw.githubusercontent.com/warpdotdev/brand-assets/refs/heads/main/Github/Sponsor/Warp-Github-LG-03.png" /></div>
<div><a href="https://go.warp.dev/zoxide"><img alt="Sponsored by Warp" width="230" src="https://raw.githubusercontent.com/warpdotdev/brand-assets/refs/heads/main/Github/Sponsor/Warp-Github-LG-03.png" /></a></div>
<div><sup><b>Warp, built for coding with multiple AI agents.</b></sup></div>
<div><sup>Available for macOS, Linux, and Windows.</sup></div>
<div><sup>

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,44 @@ 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("");
}
}
#[test]
fn murex_template_has_direct_path_handling() {
let opts = Opts { cmd: Some("z"), hook: InitHook::None, echo: false, resolve_symlinks: false };
let source = Murex(&opts).render().unwrap();
// Ensure murex z handles: "-- path" and tries direct cd on single-arg
assert!(
source.contains("if { $__zoxide_argc == 2 && $PARAMS[0] == \"--\" }"),
"murex template should handle literal path with --"
);
assert!(
source.contains("fexec function __zoxide_cd $PARAMS[0]"),
"murex template should attempt cd directly on single-arg"
);
// Ensure __zoxide_zi exists (interactive-only)
assert!(
source.contains("fexec builtin function __zoxide_zi"),
"murex template should define __zoxide_zi"
);
}
#[apply(opts)]
fn tcsh_tcsh(cmd: Option<&str>, hook: InitHook, echo: bool, resolve_symlinks: bool) {
let opts = Opts { cmd, hook, echo, resolve_symlinks };

114
templates/murex.txt Normal file
View File

@ -0,0 +1,114 @@
{%- let section = "# =============================================================================\n#" -%}
{%- let not_configured = "# -- not configured --" -%}
{{ section }}
# Utility functions for zoxide.
#
# cd + custom logic based on the value of _ZO_ECHO.
fexec builtin function __zoxide_cd {
fexec builtin cd $PARAMS[0]
{%- if echo %}
fexec builtin out $PWD
{%- endif %}
}
{{ section }}
# Hook configuration for zoxide.
#
{% match hook %}
{%- when InitHook::None -%}
{{ not_configured }}
{%- when InitHook::Prompt -%}
# Initialize hook to add new entries to the database.
fexec builtin event onPrompt __zoxide_hook=command-completion {
exec zoxide add -- $PWD
}
{%- when InitHook::Pwd -%}
# Emulate a PWD hook by tracking the last directory and updating on prompt.
fexec builtin out $PWD -> global: str __zoxide_oldpwd
fexec builtin event onPrompt __zoxide_hook=command-completion {
# Initialize global if missing (eg new session or cleared state)
if { !$__zoxide_oldpwd } then { fexec builtin out $PWD -> global: str __zoxide_oldpwd }
if { $__zoxide_oldpwd != $PWD } then {
fexec builtin out $PWD -> global: str __zoxide_oldpwd
exec zoxide add -- $PWD
}
}
{%- endmatch %}
{{ section }}
# When using zoxide with --no-cmd, alias these internal functions as desired.
#
# Jump to a directory using only keywords.
fexec builtin function __zoxide_z {
__zoxide_argc = 0
trypipe <!null> { @PARAMS -> count -> set int __zoxide_argc }
if { $__zoxide_argc == 0 } then { fexec function __zoxide_cd $HOME; fexec builtin return }
if { $PARAMS[0] == "-" } then {
fexec function __zoxide_cd -
fexec builtin return
}
# If a literal path is provided with "--", cd to it directly.
if { $__zoxide_argc == 2 && $PARAMS[0] == "--" } then {
fexec function __zoxide_cd $PARAMS[1]
fexec builtin return
}
# If a single argument is provided, try cd directly; if it fails, fall back to query.
if { $__zoxide_argc == 1 } then {
trypipe <!null> {
fexec function __zoxide_cd $PARAMS[0]
fexec builtin return
}
}
# Quiet query: capture result; suppress noise; return 1 on no match
fexec builtin out '' -> set: str __zoxide_result
trypipe <!null> {
exec zoxide query --exclude $PWD -- @PARAMS -> set: str __zoxide_result
}
if { $__zoxide_result } then {
fexec function __zoxide_cd $__zoxide_result
} else {
fexec builtin return 1
}
}
# Jump to a directory using interactive search.
fexec builtin function __zoxide_zi {
# Interactive query; return 1 when no selection
fexec builtin out '' -> set: str __zoxide_result
trypipe <!null> {
exec zoxide query --interactive -- @PARAMS -> set: str __zoxide_result
}
if { $__zoxide_result } then {
fexec function __zoxide_cd $__zoxide_result
} else {
fexec builtin return 1
}
}
{{ 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 shell configuration file (usually ~/.murex_profile):
#
# zoxide init murex -> source