kamiyaa / joshuto

ranger-like terminal file manager written in Rust
https://crates.io/crates/joshuto
GNU Lesser General Public License v3.0
3.47k stars 154 forks source link

[Feature Request] use zoxide for cd functions #97

Closed jtrv closed 2 years ago

jtrv commented 3 years ago

I think it could be beneficial to replace cd functions with an implementation of zoxide since it is written in rust and works the same as cd with some really great additional functionality

zoxide is a blazing fast replacement for your cd command, inspired by z and autojump. It keeps track of the directories you use most frequently, and uses a ranking algorithm to navigate to the best match. tutorial

kamiyaa commented 3 years ago

I will need to investigate further on the viability of this. The main issue being zoxide is a standalone program and doesn't provide any integration with other rust applications. So I'm thinking interacting with it will require a lot of spawning child processes and reading/writing from stdin/stdout.

ajeetdsouza commented 2 years ago

@kamiyaa if it helps, there are a bunch of file managers that already provide zoxide functionality via the CLI itself, and it does not appear to impact user experience:

xplr and felix are both written in Rust, just like joshuto.

kamiyaa commented 2 years ago

@ajeetdsouza Thanks! I think I have a good idea on how to implement this now :+1: Should be implemented soon everyone!

ajeetdsouza commented 2 years ago

Sounds great! I'd be happy to feature joshuto on zoxide's README once this lands.

kamiyaa commented 2 years ago

joshuto now has initial integration with zoxide in dev branch (https://github.com/kamiyaa/joshuto/commit/7ad3eb1823556107cd412bb25d4f8e95931354e0). Feel free to test it out and let me know how it is. I haven't used zoxide a lot myself so I'm not sure if I am covering everything xd.

You can find the commands for it here: https://github.com/kamiyaa/joshuto/blob/dev/docs/configuration/keymap.toml.md#integration

DLFW commented 2 years ago

Hi! Side question: like in the CI, dev branch doesn’t build with latest nightly for me:

error[E0308]: mismatched types
  --> src/ui/widgets/tui_file_preview.rs:43:46
   |
43 |                     buf.set_spans(area.x, y, line, area.width);
   |                                              ^^^^ expected struct `Spans`, found struct `tui::text::Spans`
   |
   = note: expected reference `&Spans<'_>`
              found reference `&tui::text::Spans<'_>`
   = note: perhaps two different versions of crate `tui` are being used?

For more information about this error, try `rustc --explain E0308`.
error: could not compile `joshuto` due to previous error

I think that error is there since some time. Am I missing something?

kamiyaa commented 2 years ago

Hi! Side question: like in the CI, dev branch doesn’t build with latest nightly for me:

error[E0308]: mismatched types
  --> src/ui/widgets/tui_file_preview.rs:43:46
   |
43 |                     buf.set_spans(area.x, y, line, area.width);
   |                                              ^^^^ expected struct `Spans`, found struct `tui::text::Spans`
   |
   = note: expected reference `&Spans<'_>`
              found reference `&tui::text::Spans<'_>`
   = note: perhaps two different versions of crate `tui` are being used?

For more information about this error, try `rustc --explain E0308`.
error: could not compile `joshuto` due to previous error

I think that error is there since some time. Am I missing something?

You might have ansi-to-tui as a dependency, which uses an older version of tui-rs. I removed ansi-to-tui as a default dependency for now because it's a bit buggy.

ajeetdsouza commented 2 years ago

@kamiyaa it works great! I have a few suggestions/nitpicks:

kamiyaa commented 2 years ago

@kamiyaa it works great! I have a few suggestions/nitpicks:

* Currently, zoxide fails silently. zoxide will give you errors over stderr, eg. `zoxide: no match found`. Perhaps this can be captured and dispayed.

* You may want to call `zoxide add` if `z`/`zi` succeeds.

* Instead of using `trim()`, a more "correct" way to do it would be removing the last byte from the output of `zoxide query` (trailing newline). `trim` will fail on directories where the paths teminate in a space, for example.

* When `z {}` is displayed, it looks strange on directories with spaces in the name, because it's not quoted (eg, `z /this/looks like/multiple arguments`). Instead, you could either just show the path without printing `z`, or add quoting using `z {:?}`/[shell-words](https://crates.io/crates/shell-words).

Thanks @ajeetdsouza ! I've addressed all these issues now :+1:

https://github.com/kamiyaa/joshuto/commit/8e7005ac347d0ef06af83e87874c824aa432da42

ajeetdsouza commented 2 years ago

Awesome, thanks!