joshuto icon indicating copy to clipboard operation
joshuto copied to clipboard

Problem with the file chooser argument

Open Rolv-Apneseth opened this issue 1 year ago • 9 comments

I hope I'm not being blind but I can't find how to use the --file-chooser argument for this program. It is not mentioned in this doc page.

When I run joshuto --file-chooser, the program works fine but exits with an error (102) after selecting a file. I would expect it to either output straight to stdout or take an output file as an argument, so though I'm not even sure it makes sense, I also tried joshuto --file-chooser --output-file temp.txt and the result is the same.

Any support would be appreciated, thanks.

Rolv-Apneseth avatar Nov 28 '23 22:11 Rolv-Apneseth

I didn't know about this feature, and because I'm very interested in it, I can see if I find some clues

topongo avatar Nov 29 '23 09:11 topongo

Hi! Try this:

joshuto --file-chooser --output-file ~/my-temp-file

The selected file is written to the given temp-file.

It's for example used in this NeoVim plugin, which add Joshuto as a way to open a file.

DLFW avatar Nov 29 '23 20:11 DLFW

Ah yes that seems to work thanks. It does still exit with an error though but I guess as long as it works it's fine.

And that's funny, thanks for sharing that plugin, that's exactly the kind of thing I was looking to do

Rolv-Apneseth avatar Nov 29 '23 21:11 Rolv-Apneseth

Hmmm, not exactly an error, I guess: https://github.com/kamiyaa/joshuto/blob/6cabeb9c8308e5debc9eda3ef8dadda268545156/src/commands/quit.rs#L22C20-L22C20

If this is really not documented somewhere, I agree, it should be...

DLFW avatar Nov 29 '23 21:11 DLFW

I don't know much about exit codes to be honest, but shouldn't it be 0 if there was no problem with the operation?

Rolv-Apneseth avatar Nov 29 '23 21:11 Rolv-Apneseth

Hmmm, not exactly an error, I guess: https://github.com/kamiyaa/joshuto/blob/6cabeb9c8308e5debc9eda3ef8dadda268545156/src/commands/quit.rs#L22C20-L22C20

If this is really not documented somewhere, I agree, it should be...

Yeah, I should document it somewhere

kamiyaa avatar Dec 19 '23 15:12 kamiyaa

I don't know much about exit codes to be honest, but shouldn't it be 0 if there was no problem with the operation?

Yeah, usually 0 means success. Non-zero means an error, but can also be used to communicate other things

kamiyaa avatar Dec 19 '23 15:12 kamiyaa

Should this be println! and not eprintln!? Personally, I'd rather have this sent to stdout than stderr. Also, for some reason the file list doesn't even output to stderr as-is, but when I recompile with println! instead, the files display to stdout as expected.

https://github.com/kamiyaa/joshuto/blob/2536838ce31955ec55561aabb4b86fdd4bc984df/src/main.rs#L219

dgmcdona avatar Mar 15 '24 22:03 dgmcdona

Should this be println! and not eprintln!? Personally, I'd rather have this sent to stdout than stderr. Also, for some reason the file list doesn't even output to stderr as-is, but when I recompile with println! instead, the files display to stdout as expected.

https://github.com/kamiyaa/joshuto/blob/2536838ce31955ec55561aabb4b86fdd4bc984df/src/main.rs#L219

ratatui/termion (not sure which one) doesn't allow for joshuto's output to be piped.

This makes it a bit tricky to get joshuto to work with shell scripts. Because you can't just do file_path=$(joshuto --file-chooser) because the output is piped.

So the only other option is to pipe it to a file.

joshuto --file-chooser > some_file.txt

But this won't work either because joshuto outputs to stdout, which gets piped to the file.

So the only sensible solution is to have

joshuto --file-chooser 2> some_file.txt

Hope this clears things up!

kamiyaa avatar Apr 03 '24 17:04 kamiyaa