broot icon indicating copy to clipboard operation
broot copied to clipboard

Your inputs for a cookbook

Open Canop opened this issue 5 years ago • 54 comments

There seems to be the need for a list of recipes, including

  • some hotkey sets, for example vi or emacs related
  • some alternate openers
  • some very special installations
  • some skins
  • some tricks, or non obvious uses of broot
  • etc.

Please share what, in your opinion, could be included in there.

Answer with either a recipe, part of a recipe, or a need for some specific one.

Canop avatar Jan 13 '20 12:01 Canop

I'm a big fan of

[[verbs]]
key = "left"
execution = ":parent"

[[verbs]]
key = "right"
execution = ":focus"

briangordon avatar Jan 13 '20 16:01 briangordon

This should be a default!

kakulukia avatar Jan 14 '20 19:01 kakulukia

@kakulukia the reason why it's hard to make it a default:

  • vim-like addicted users are very able to tune the config if we provide them a cookbook
  • normal human beings would be annoyed not being able to use the arrows when editing the input

Canop avatar Jan 14 '20 19:01 Canop

hmmm .. agreed .. good point .. what about using arrow keys for editing as long as there is something to edit and use em for navigation if otherwise? even right arrow to view file?

I will definitely watch this project as it might replace three tools im currently using: ncdu, nnn, fd Well done!

BUT: br > edit file in vim > use :q to quit vim > also closing broot 😭

kakulukia avatar Jan 14 '20 21:01 kakulukia

I need also to give hints at how to do the br configuration by hand for very specific configurations.

broot --set-install-state refused --print-shell-function fish > ~/sea/br.fish

Canop avatar Jan 20 '20 18:01 Canop

@Canop similar to @kakulukia reply. I've set Enter as the default of editing it via vim/neovim. It would be cool that if I quit it I go back to broot and traverse from there. Or maybe even better is a broot plugin for vim/neovim? like how netrw is integrated via vim vinegar?

Anyway here's what I've added so far:

[[verbs]]
key = "alt-j"
execution = ":line_down"

[[verbs]]
key = "alt-k"
execution = ":line_up"

[[verbs]]
invocation = "edit"
key = "enter"
execution = "$EDITOR {file}"

chiefjester avatar Jan 27 '20 15:01 chiefjester

I note this one: overloading rm for your prefered file removal command. https://github.com/Canop/broot/issues/136#issuecomment-582269484

Canop avatar Jul 01 '20 11:07 Canop

. It would be cool that if I quit it I go back to broot and traverse from there

This is pretty much what ranger does by default.

savchenko avatar Nov 23 '20 05:11 savchenko

I like to have the PS1 prompt indicating when the shell is invoked by broot.

For this I have added to the br function in the launcher script as first line: export BROOT_ACTIVE=true and as last line, after the default content of the function: export BROOT_ACTIVE=

In my .bashrc I have added after my normal prompt settings: if test -n "$BROOT_ACTIVE"; then PS1="${PS1} (in broot) "; export PS1; fi

With this (in broot) is added to the PS1 prompt when the shell is invoked with broot.

E3D3 avatar Feb 05 '21 16:02 E3D3

Oh that's cool

Canop avatar Feb 05 '21 16:02 Canop

Thank you, but broot is much cooler. Thank you much for sharing this wonderfull program.

E3D3 avatar Feb 05 '21 16:02 E3D3

Is there a way to configure esc to quit broot while in the top level of the TUI ?

amosbird avatar May 02 '21 09:05 amosbird

Is there a way to configure esc to quit broot while in the top level of the TUI ?

Not anymore.

That was the initial behaviour, and I removed it because most people found it confusing.

If you think it could be better, create an issue, I can put it back behind a configuration flag.

Canop avatar May 02 '21 09:05 Canop

If you think it could be better, create an issue, I can put it back behind a configuration flag.

Awesome. Issue created https://github.com/Canop/broot/issues/380

amosbird avatar May 02 '21 09:05 amosbird

EDIT: This is outdated. After I figure out a couple issues, I'll post a comprehensive update.

Original

EDIT: ~This isn't quite right. I'm probably using the new import feature wrong. For example, .zle_cd-broot is not only showing folders, as I expected it to.~ FIXED


FWIW here's how I integrate this with Zsh:

.zshrc:

br () {  # [<broot-opt>...]
  emulate -L zsh

  local cmdfile=$(mktemp)
  trap "rm ${(q-)cmdfile}" EXIT INT QUIT
  if { broot --outcmd "$cmdfile" $@ } {
    if [[ -r $cmdfile ]]  eval "$(<$cmdfile)"
  } else {
    return
  }
}
bindkey -s '^b' 'br\n'  # ctrl+b

.zle_insert-path-broot () {
  echoti rmkx
  local location_space="${(q-)$(broot --color yes --conf "${HOME}/.config/broot/select.hjson;${HOME}/.config/broot/conf.hjson")} "
  BUFFER+=$location_space
  (( CURSOR+=$#location_space ))
}
zle -N .zle_insert-path-broot
bindkey '^[[1;7B' .zle_insert-path-broot  # ctrl+alt+down

.zle_redraw-prompt () {
  # Credit: romkatv/z4h
  emulate -L zsh
  for 1 ( chpwd $chpwd_functions precmd $precmd_functions ) {
    if (( $+functions[$1] ))  $1 &>/dev/null
  }
  zle .reset-prompt
  zle -R
}

.zle_cd-broot () {
  echoti rmkx
  cd "$(broot --color yes --conf "${HOME}/.config/broot/select-folder.hjson;${HOME}/.config/broot/conf.hjson")"
  .zle_redraw-prompt
}
zle -N .zle_cd-broot
bindkey '^[[1;3B' .zle_cd-broot  # alt+down

select.hjson:

{

  default_flags: ig

  verbs: [

    {
      internal: ":print_path"
      key: "enter"
      leave_broot: true
    }

  ]

}

select-folder.hjson:

{

  default_flags: igf

  verbs: [

    {
      apply_to: "directory"
      internal: ":print_path"
      key: "enter"
      leave_broot: true
    }

    {
      apply_to: "file"
      cmd: ":focus;:print_path"
      key: "enter"
      leave_broot: true
    }

  ]

}

AndydeCleyre avatar Jul 13 '22 17:07 AndydeCleyre

@AndydeCleyre I hadn't thought about this use of the imports. Can you please create an issue asking how to deal with this f flag in imports ?

Canop avatar Jul 15 '22 05:07 Canop

EDIT: This is outdated. After I figure out a couple issues, I'll post a comprehensive update.

Original

One small thing is I like cd to work on files, too (same as operating on the file's parent folder):

{
  apply_to: "file"
  cmd: ":focus;:cd"
  shortcut: cd
}

EDIT: I think this one has been triggering an infinite loop lately but it used to work.

AndydeCleyre avatar Jul 15 '22 15:07 AndydeCleyre

@AndydeCleyre Is your .zle_insert-path-broot a widget that allows you to insert a file path into a command you've started typing (like the fzf ^t widget, if you're familiar with that)? This is exactly what I'm trying to accomplish right now. Unfortunately, when I source your code, my terminal freezes when broot launches. I don't suppose you'd have any idea what's going on? My versions are

$ zsh --version
zsh 5.8.1 (x86_64-apple-darwin21.0)

$ broot --version
broot 1.16.1

fredcallaway avatar Oct 22 '22 01:10 fredcallaway

Yes, that's how it works here. Are the config files set up? Maybe something's wrong with the mode, and you should comment out echoti rmkx? You could try launching zsh as zsh --noglobalrcs?

AndydeCleyre avatar Oct 22 '22 04:10 AndydeCleyre

No luck... :\ I've also tried with zsh -dfi so I don't think it's due to some other configuration I have set up.

I should mention that I had the same problem with a simpler version I started hacking on which simply calls broot from a widget. Mysterious, and a real bummer because this setup would be amaaazing.

Anyway, thanks for your help.

fredcallaway avatar Oct 22 '22 04:10 fredcallaway

Does this work?

$ podman run --net=host -it -e TERM=$TERM --rm docker.io/library/alpine:edge
# apk add broot zsh
# exec zsh
# mkdir -p ~/.config/broot
# <<'EOF' >~/.config/broot/select.hjson
{

  default_flags: ig

  verbs: [

    {
      internal: ":print_path"
      key: "enter"
      leave_broot: true
    }

  ]
}
EOF
# <<'EOF' >~/.zshrc
.zle_insert-path-broot () {
  echoti rmkx
  local location_space="${(q-)$(broot --color yes --conf "${HOME}/.config/broot/select.hjson")} "
  BUFFER+=$location_space
  (( CURSOR+=$#location_space ))
}
zle -N .zle_insert-path-broot
bindkey '^[[1;7B' .zle_insert-path-broot
EOF
# exec zsh

Then trying the bindkey?

If not, what about a different terminal app?

AndydeCleyre avatar Oct 23 '22 04:10 AndydeCleyre

I'm not familiar with podman (or containers generally). Should I be able to just paste this into a terminal after installing? I get Error: failed to connect: dial tcp [::1]:49215: connect: connection refused from the first line.

fredcallaway avatar Oct 23 '22 17:10 fredcallaway

For anyone else who happens to land here, the problem is specific to macos (I'm running 12.3.1) and is not specific to broot. It occurs with many but not all other TUI apps.

If anyone knows what's going on here, I'd appreciate any pointers. I haven't gotten anywhere with google (there's not a whole on ZLE widgets in general....)

fredcallaway avatar Mar 08 '23 22:03 fredcallaway

@fredcallaway Any change if you try installing a newer Zsh release, via brew?

I'm noticing btw that my insert-path widget assumes you want it at the end of the line, and I should probably update it to insert wherever the cursor is instead.

AndydeCleyre avatar Mar 09 '23 20:03 AndydeCleyre

Sadly, no. Same behavior with 5.9 (x86_64-apple-darwin21.3.0)

fredcallaway avatar Mar 12 '23 05:03 fredcallaway

@fredcallaway Sorry to hear that. I suggest posting on the Zsh subreddit or IRC channel.

AndydeCleyre avatar Mar 14 '23 03:03 AndydeCleyre

The solution to the frozen terminal issue (provided by @AndydeCleyre on reddit) is to add <$TTY before broot, e.g.

.zle_insert-path-broot () {
  echoti rmkx
  local location_space="${(q-)$(<$TTY broot --color yes --conf "${HOME}/.config/broot/select.hjson;${HOME}/.config/broot/conf.hjson")} "
  BUFFER+=$location_space
  (( CURSOR+=$#location_space ))
}

fredcallaway avatar Apr 01 '23 10:04 fredcallaway

@fredcallaway Can you give me the link to the reddit thread ?

Canop avatar Apr 01 '23 11:04 Canop

https://reddit.com/r/zsh/comments/11tzgqz/_/jd8zguz/?context=1

@Canop

fredcallaway avatar Apr 02 '23 07:04 fredcallaway

I'm a big fan of

[[verbs]]
key = "left"
execution = ":parent"

[[verbs]]
key = "right"
execution = ":focus"

Even when I try setting that verb for right, if I have filter text typed, it won't focus. Is there a way to make right always focus?

AndydeCleyre avatar Oct 24 '23 21:10 AndydeCleyre