joshuto
joshuto copied to clipboard
Image Preview with kitty
I love joshuto but I just cannot get the image previewing to work on joshuto. I looked at the documenation for inage previewing and it just doesnt work. Is there some way to append and make the image preview docs more coherent and making sure that it works? Thanks
Hi, agree, the docs could be better. “Making sure that it works” might be a bit hard, though. :smile:
I just realized the Kitty section in the image-preview-docs does not explain the whole thing but only the Kitty-specific part.
Have you configured the two hook-script in your joshuto.toml
as explained in the upper Überzug section?
If the hooks are not configured, Joshuto won't invoke them.
If you already did that, maybe put some echo foo >> /tmp/bar
or something in your hook-scripts to check if they are really called from Joshuto. Then we would at least know if the problem is on the Joshuto-side (if they are not called), or in the scripts.
Note: The Kitty-section states that the preview_file.sh
must return 5
in order to get the image previews. I think that's wrong. As far as I can remember, the preview_script.sh
script is independent from the image preview. The hook scripts are called when they are configured (and executable!), not matter what the preview_file.sh
returns.
Since I don't personally use kitty, it is mostly left to the community to create docs on the topic. :+1:
I will however, make more documentation on previews
Hi, agree, the docs could be better. “Making sure that it works” might be a bit hard, though. smile
I just realized the Kitty section in the image-preview-docs does not explain the whole thing but only the Kitty-specific part. Have you configured the two hook-script in your
joshuto.toml
as explained in the upper Überzug section? If the hooks are not configured, Joshuto won't invoke them.If you already did that, maybe put some
echo foo >> /tmp/bar
or something in your hook-scripts to check if they are really called from Joshuto. Then we would at least know if the problem is on the Joshuto-side (if they are not called), or in the scripts.Note: The Kitty-section states that the
preview_file.sh
must return5
in order to get the image previews. I think that's wrong. As far as I can remember, thepreview_script.sh
script is independent from the image preview. The hook scripts are called when they are configured (and executable!), not matter what thepreview_file.sh
returns.
Hi, i seem to be having the same problem as GingerGengar, it doesn't seem like the scripts are ever called even if i did put the [preview] section in joshuto.toml with the two hooks. Do i need to write a wrapper like the one for uberzug?
Hm, just tried it out with latest from main
and it still works for me.
One idea: Check and maybe increase max_preview_size
. I have set that to 50000097152
to just have all my preview's working (also text previews like meta-data for videos, etc.).
Oh, and
Do i need to write a wrapper like the one for uberzug?
no.
So sorry for the late reply. Yepp I already configured the 2 build hooks just like the example, even copy pasting exactly the files. I added the echo "foo" command on both hooks and none of them got called, so it seems that joshuto doesnt even call the scripts. Also uberzung is also deprecated. I also changed the max_preview_size and it still didnt help. Please advise what I should do, thank you.
The hook scripts must be called if they are executable and configured correctly without a typo. There is no magic there. Something is really fishy here.
- What version of Joshuto are you using? It's not by any chance super-old???
- Are you sure the hook-scripts are executable and the configured paths are correct?
- Are you sure that the hook-scripts are not executed? Have you looked at the right place for the output of
echo foo...
? Have you tried another option to check that? Maybe likenotify-send Hello!
or whatever?
I have added my icat-test-hooks to my dotfile repo.
You may have a look and try with them.
You have to comment-out the Überzug-hooks and comment-in the icat-hooks in joshuto.toml
.
Again, if you download my dots manually, take care that the hooks are executable.
If that doesn't help you, please publish your dots somewhere or paste your joshuto.toml
and the output of ls -alF ~/.config/joshuto
here.
I've got it working by looking at the gitlab from the previous message but the docs here https://github.com/kamiyaa/joshuto/blob/main/docs/image_previews.md aren't structured in a logical way imo, there are 2 ways to achieve the preview : Uberzug and Icat, one shouldn't have to look at instructions under th Uberzug title to get icat's related ones. Here if you jump to Kitty and skip Uberzug you don't even know that you have to link those scripts in joshuto.toml
.
Maybe linking @DLFW dotfiles would clarify this ?
Linking to my dotfiles would be an honor for me :smile:, but I think restructuring the documentation would be better. Anybody keen to do so? Also the other documentation could have some cleanup. Maybe it would have a great value to restructure the complete docs and maybe publish it via mkdocs or something similar as GitHub-Page.
@GingerGengar, any update? Otherwise I would propose to close....
BTW, some restructuring of the image preview documentation done in #359.
@DLFW I'm on Mac. I use kitty 0.28.1 and joshuto 0.9.5. I configured exactly like what the doc said, but image preview is not working.
joshuto.toml
:
[preview]
max_preview_size = 50000097152 # 2MB
preview_script = "~/.config/joshuto/preview_file.sh" # make sure it's marked as executable
preview_shown_hook_script = "~/.config/joshuto/on_preview_shown"
preview_removed_hook_script = "~/.config/joshuto/on_preview_removed"
~/.config/joshuto
$ ls -alF
total 20
drwxr-xr-x 6 juhan staff 192 Jul 14 22:57 ./
drwxr-xr-x 22 juhan staff 704 Jul 14 22:17 ../
-rw-r--r-- 1 juhan staff 935 Jul 15 08:26 joshuto.toml
-rwxr-xr-x 1 juhan staff 87 Jul 14 22:31 on_preview_removed*
-rwxr-xr-x 1 juhan staff 858 Jul 15 08:30 on_preview_shown*
-rwxr-xr-x 1 juhan staff 6918 Jul 15 08:20 preview_file.sh*
~/.config/joshuto
$ cat on_preview_shown
#!/usr/bin/env bash
FILE_PATH="$1" # Full path of the previewed file
PREVIEW_X_COORD="$2" # x coordinate of upper left cell of preview area
PREVIEW_Y_COORD="$3" # y coordinate of upper left cell of preview area
PREVIEW_WIDTH="$4" # Width of the preview pane (number of fitting characters)
PREVIEW_HEIGHT="$5" # Height of the preview pane (number of fitting characters)
TMP_FILE="$HOME/.cache/joshuto/thumbcache.png"
mimetype=$(file --mime-type -Lb "$FILE_PATH")
function image {
kitty +kitten icat \
--transfer-mode=file \
--clear 2>/dev/null
kitty +kitten icat \
--transfer-mode=file \
--place "${PREVIEW_WIDTH}x${PREVIEW_HEIGHT}@${PREVIEW_X_COORD}x${PREVIEW_Y_COORD}" \
"$1" 2>/dev/null
}
case "$mimetype" in
image/*)
image "${FILE_PATH}"
;;
*)
kitty +kitten icat \
--transfer-mode=file \
--clear 2>/dev/null
;;
esac
~/.config/joshuto
$ cat on_preview_removed
#!/usr/bin/env bash
kitty +kitten icat \
--transfer-mode=file \
--clear 2>/dev/null
@DLFW Never mind. I figured it out. Have to install exiftool
and tweak preview_file.sh
a little bit. Seems like preview_file.sh
is called before two hook scripts.
@DLFW any chance we can get image preview working inside tmux? I know ranger has a related patch.
I figured it out. Have to install
exiftool
and tweakpreview_file.sh
a little bit. Seems likepreview_file.sh
is called before two hook scripts.
Yes, it is. And only when you return with 0
from the preview script, Joshuto will show the preview-area. And only when the preview area is shown, the hook-script is called. I think it would have been enough to just exit 0
before the exiftool
-call, if you don't want any “textual preview” (e.g. meta data) beside the image preview.
any chance we can get image preview working inside tmux?
I think so, yes. I don't use tmux myself but the hook scripts are just scripts. So you can do whatever you want. You can also switch on your coffee-machine over MQTT when you hover over an image that is called coffee.jpg
. So, without knowing tmux, I think that should absolutely be doable. Unlike ranger, Joshuto does not integrate any image-preview solution (yet). It's solely up to the user what they do in the hook-scripts.
@kamiyaa: Image preview in Kitty is working. Considering Überzug++'s Kitty backend, it's even working in two different ways. Propose to close this issue.
For me, the issue was that because of the exit 1
at the end of preview_file.sh
, the image hooks were actually not called. Changing it to exit 0
made image preview work (joshuto keeps trying with the image script).