Open AndydeCleyre opened 1 year ago
I confirm that this looks like a zsh specific problem:
I'm not sure what the generated outcmd looks like. Is it generated specifically depending on the shell, or is the same outcmd used regardless of shell? And I really don't know how the filename gets formatted/inserted...
If it's shell-aware, for zsh it might be a good idea to:
print -rl -- FILENAME $'\0' | read -d $'\0' itsaname
cd ${(q-)itsaname}
The function used for zsh is defined here: https://github.com/Canop/broot/blob/master/src/shell_install/bash.rs#L31
If you're willing to investigate and try a better general solution, go ahead, I'm a little too busy atm.
Thanks, I'll look around. But I'm not so much wondering about the br
function as the outcmd generation.
EDIT: found cmd_result_exec_from_parent_shell
, will take a closer look.
EDIT: even more relevant: shell_exec_string
Can you replace the Zsh-specific cd
command with noglob cd
?
$ mkdir '[nopat]'
$ cd [nopat]
zsh: no matches found: [nopat]
$ noglob cd [nopat]
$ pwd
/home/andy/[nopat]
If broot's cd
verb always operates on a literal path, it should never need a glob, so it seems safe enough.
@AndydeCleyre Would that entry in verbs.hjson solve the problem for zsh users ?
{
key: alt-enter
external: "noglob cd {file}"
from_shell: true
}
That verb works, yes.
But I don't use a shortcut and rely on typing :cd
. I currently override the :cd
behavior for files so that it works on that file's parent:
{
apply_to: "file"
cmd: ":focus;:cd"
shortcut: cd
}
But reviewing the docs and this conversation, it seems I can replace that with:
{
external: "noglob cd {directory}"
invocation: cd
from_shell: true
}
And it all seems to work. Thanks!
Now the question is how to make this verb discoverable by zsh users...
{
external: "noglob cd {directory}"
key: alt-enter
invocation: cd
from_shell: true
}
This problem can now (>1.33.1
) also be avoided by using the following verb:
{
key: alt-enter
invocation: cd
cmd: ":write_output {directory};:quit"
}
with the following launcher function (Zsh):
zmodload zsh/mapfile
# -- Run broot, cd into pathfile if successful --
# Depends: zmapfile
br () { # [<broot-opt>...]
emulate -L zsh
local pathfile=$(mktemp)
trap "rm ${(q-)pathfile}" EXIT INT QUIT
if { broot --verb-output "$pathfile" $@ } {
if [[ -r $pathfile ]] {
local folder=${mapfile[$pathfile]}
if [[ $folder ]] cd $folder
}
} else {
return
}
}
In broot, use verb
cd
on the folder named[notapattern]