Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Your inputs for a cookbook #152

Open
Canop opened this issue Jan 13, 2020 · 53 comments
Open

Your inputs for a cookbook #152

Canop opened this issue Jan 13, 2020 · 53 comments
Labels
help wanted Extra attention is needed

Comments

@Canop
Copy link
Owner

Canop commented Jan 13, 2020

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 Canop added the help wanted Extra attention is needed label Jan 13, 2020
@briangordon
Copy link

I'm a big fan of

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

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

@kakulukia
Copy link

This should be a default!

@Canop
Copy link
Owner Author

Canop commented Jan 14, 2020

@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

@kakulukia
Copy link

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 😭

@Canop
Copy link
Owner Author

Canop commented Jan 20, 2020

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

@chiefjester
Copy link

@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}"

@Canop Canop pinned this issue Feb 5, 2020
@Canop
Copy link
Owner Author

Canop commented Jul 1, 2020

I note this one: overloading rm for your prefered file removal command.
#136 (comment)

@savchenko
Copy link

. 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.

@E3D3
Copy link

E3D3 commented Feb 5, 2021

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.

@Canop
Copy link
Owner Author

Canop commented Feb 5, 2021

Oh that's cool

@E3D3
Copy link

E3D3 commented Feb 5, 2021

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

@amosbird
Copy link

amosbird commented May 2, 2021

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

@Canop
Copy link
Owner Author

Canop commented May 2, 2021

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.

@amosbird
Copy link

amosbird commented May 2, 2021

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

Awesome. Issue created #380

@AndydeCleyre
Copy link

AndydeCleyre commented Jul 13, 2022

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
    }

  ]

}

@Canop
Copy link
Owner Author

Canop commented Jul 15, 2022

@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 ?

@AndydeCleyre
Copy link

AndydeCleyre commented Jul 15, 2022

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.

@fredcallaway
Copy link

@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

@AndydeCleyre

This comment was marked as off-topic.

@fredcallaway
Copy link

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.

@AndydeCleyre

This comment was marked as off-topic.

@fredcallaway
Copy link

fredcallaway commented Oct 23, 2022

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
Copy link

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....)

@AndydeCleyre

This comment was marked as off-topic.

@fredcallaway
Copy link

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 ))
}

@Canop
Copy link
Owner Author

Canop commented Apr 1, 2023

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

@fredcallaway
Copy link

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

@Canop

@AndydeCleyre
Copy link

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
Copy link

Alright, aside from the above comment, I've settled my broot+zsh configs for now, at repos dotfiles-broot and dotfiles-zsh (mostly broot.zsh).

@fredcallaway FYI I added a bunch of complexity to .zle_insert-path-broot, so that it'll work great even if you trigger it with a partially typed path on the line already.

@Canop
Copy link
Owner Author

Canop commented Nov 4, 2023

@AndydeCleyre

Even when I try setting that verb for right, if I have filter text typed, it won't focus.

How would you move the selection caret in the input ?

@AndydeCleyre
Copy link

@AndydeCleyre

Even when I try setting that verb for right, if I have filter text typed, it won't focus.

How would you move the selection caret in the input ?

99-100% of the time my cursor is already as far right as can be. So I'd be happy if I could get right to, in this case that the cursor cannot possibly move further right, focus instead. If that's not possible, I'd still be happy to completely forgo the ability to move the cursor to the right in any case, in order to get right to focus.

@Canop
Copy link
Owner Author

Canop commented Nov 5, 2023

Right now, the left and right keys aren't evaluated to verbs when the input isn't empty. I could change this to forbid the left key when the caret isn't at left, and the right key when the caret isn't at right.

@Canop
Copy link
Owner Author

Canop commented Nov 5, 2023

@AndydeCleyre done in main. Will be part of the next release

@Martin1887
Copy link

I think that fzf-like files and folders selection in Broot are a must in the web and the wiki (and maybe even installable like br)!

Maybe https://github.com/AndydeCleyre/dotfiles-zsh/blob/main/broot.zsh is too opinionated, but having a shortcut to search files and another one for directories is really useful, and another one to temporally show Broot without returning nothing is also useful.

Thanks for this great project!

@Canop
Copy link
Owner Author

Canop commented Dec 16, 2023

Those sets of shortcut deserve probably more than just an entry in broot's doc: blog posts with a detailed presentation.

@Martin1887
Copy link

What do you think about this and creating a blog post, @AndydeCleyre?

@AndydeCleyre
Copy link

Ok I'll put something together, post it back here for feedback, then post it for real somewhere.

@AndydeCleyre
Copy link

@Martin1887 and anyone else interested,

I've put up a draft post at this-and-that/broot-zsh,
and any feedback is very welcome.

It's much longer than I wanted it to be, really, and I still don't know if it answers the actual questions people will have.

@Martin1887
Copy link

It looks great! The only inconvenience I see is the last part before bonus is very complex, maybe a easier though less powerful manner could be introduced just before.

Could your Ctrl+B do the trick, or it deletes the whole line (in that case, could be easily created a variant that does not delete the line)?

And the bonus part would be amazing, if removing the need of eval is finally achieved!

@AndydeCleyre
Copy link

@Martin1887

Thanks so much!

Yes, I'll add in a much simpler version which only inserts, and does not handle a partially typed path at all.

@Martin1887
Copy link

Great improvement the simple selector! It helps to understand what each thing of the complex one does.

So the only pending change is the eval-avoid function, right? I think this post should be promoted in the web, but I would change the eval-avoid empty code blocks by a more explicit message, since it may seem a failure of the user's browser.

@AndydeCleyre
Copy link

Thanks @Martin1887

Yeah, unless there's more feedback, the bonus section is all that's left.

I could remove it, or if @Canop expects to implement #825 and release soon, I'll wait for that and specify that the bonus method and config require that latest release.

@Canop
Copy link
Owner Author

Canop commented Jan 20, 2024

I expect to do it soonish. I must finish and wrap #826 before, but then it's next in the list for broot unless new bugs come in.

@AndydeCleyre
Copy link

AndydeCleyre commented Feb 21, 2024

Alright @Martin1887

Since @Canop has merged in the new features to main, I've updated and "finalized" the post (I'm still open to edits based on further feedback), even though the next broot release is still to come. The address is the same as before.

@Martin1887
Copy link

Great! I'm eager to try it (probably this week), thanks!

@Martin1887
Copy link

Martin1887 commented Mar 2, 2024

I have found a small issue in the drill-down launcher, @AndydeCleyre: at least in Starship after changing the folder it is not reflected in the prompt, but the directory is already changed. After any command (included an empty one) the directory is updated in the prompt.

Thanks!

@AndydeCleyre
Copy link

AndydeCleyre commented Mar 2, 2024

Thanks @Martin1887

Did you also add the .zle_redraw-prompt function? That's what I would expect to take care of that issue.

@Martin1887
Copy link

Martin1887 commented Mar 2, 2024

My bad, I forgot copying that function :S, now it works flawlessly, awesome!

@AndydeCleyre
Copy link

I made it too easy to skip. I've now moved it up and made it hard to skip. Thanks!

@Martin1887
Copy link

I have been using everything of the blog (and some additional verbs) flawlessly, thanks! However, the verb from #738 does not work, broot says it must be used as br. Any tip to solve this problem?

@AndydeCleyre
Copy link

@Martin1887

I use zsh-z so will try to get that going.

I think ideally we wouldn't exit the initial broot process, so that we can for example go back in history after jumping.

I can use an external to get a path result from zsh-z to the stdout of that external, but I don't know how to capture the external's stdout into a variable we can use in the same verb definition's internal or cmd entries.

@Canop What might make sense for setting a verb-usable variable from the result of an external process? Some variant of external? Or some substitution syntax like $()... or some more use of write_output with a new read_output, so it's like a scratch space that can be loaded into a variable? Or did I in fact entirely miss a better/existing approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

10 participants