joshuto icon indicating copy to clipboard operation
joshuto copied to clipboard

Image Preview with kitty

Open GingerGengar opened this issue 1 year ago • 16 comments

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

GingerGengar avatar Apr 05 '23 12:04 GingerGengar

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.

DLFW avatar Apr 17 '23 20:04 DLFW

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

kamiyaa avatar Apr 17 '23 22:04 kamiyaa

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.

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?

Locorock avatar Apr 21 '23 23:04 Locorock

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

DLFW avatar Apr 23 '23 08:04 DLFW

Oh, and

Do i need to write a wrapper like the one for uberzug?

no.

DLFW avatar Apr 27 '23 20:04 DLFW

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.

GingerGengar avatar May 04 '23 02:05 GingerGengar

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

DLFW avatar May 04 '23 18:05 DLFW

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 ?

StitiFatah avatar May 28 '23 22:05 StitiFatah

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.

DLFW avatar May 29 '23 12:05 DLFW

@GingerGengar, any update? Otherwise I would propose to close....

BTW, some restructuring of the image preview documentation done in #359.

DLFW avatar Jul 12 '23 21:07 DLFW

@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

BigBrotherJu avatar Jul 15 '23 00:07 BigBrotherJu

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

BigBrotherJu avatar Jul 15 '23 00:07 BigBrotherJu

@DLFW any chance we can get image preview working inside tmux? I know ranger has a related patch.

BigBrotherJu avatar Jul 15 '23 01:07 BigBrotherJu

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.

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.

DLFW avatar Jul 15 '23 19:07 DLFW

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

DLFW avatar Jul 15 '23 19:07 DLFW

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

frigaut avatar Jul 24 '23 14:07 frigaut