diff options
author | Jeff Zhao <jeff.no.zhao@gmail.com> | 2022-09-08 19:27:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-08 19:27:59 -0400 |
commit | fd92d14ff394ebcf7ea72b8bd9f3cf80609ceef0 (patch) | |
tree | 7eadc805981220ebc216b01ae3148760d5438ae2 | |
parent | 30111d20afc16c31a74afb7cf134f4ad8f1ade18 (diff) |
Update image_previews.md
-rw-r--r-- | docs/image_previews.md | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/docs/image_previews.md b/docs/image_previews.md index 8399281..41e05e8 100644 --- a/docs/image_previews.md +++ b/docs/image_previews.md @@ -233,25 +233,35 @@ To preview images in Kitty, you need to create these two scripts and make them e ```shell #!/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" -file="$1" -X="$2" -Y="$3" -width="$4" -height="$5" +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 "${width}x${height}@${X}x${Y}" "$1" 2>/dev/null + 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 $(file -b --mime-type "${file}") in +case "$mimetype" in image/*) - image "${file}" + image "${FILE_PATH}" + ;; + *) + kitty +kitten icat \ + --transfer-mode=file \ + --clear 2>/dev/null ;; - *) - kitty +kitten icat --transfer-mode=file --clear 2>/dev/null esac ``` @@ -259,7 +269,9 @@ esac ```shell #!/usr/bin/env bash -kitty +kitten icat --transfer-mode=file --clear 2>/dev/null +kitty +kitten icat \ + --transfer-mode=file \ + --clear 2>/dev/null ``` The first script will use icat to place an image on top of joshuto's preview window. @@ -269,6 +281,16 @@ The second script simply clears any existing images on the screen. Thats it. Previewing images should now work whenever you select a file. +NOTE: make sure the `preview_file.sh` script returns 5 exit code when previewing images in order for this to work: + +```sh +... +handle_mime() { + ... + exit 5 +} +``` + ## Kitty Demo: ![Demo](https://user-images.githubusercontent.com/57725322/150659504-203c7175-4bee-4e46-b5c5-16cc16a51a12.png) |