Closed Beethoven-n closed 1 year ago
Hi, your Issues leaves me with a lot of questions.
You're using some script based on the Überzug-example from this repo?
Well, yes, it should be pretty obvious from the show_image
function in the wrapper script. There is some argument that is given to Überzug and Überzug needs to find that file. The wrapper script is started first in the respective working directory. It has nothing to do with the directories you might change to in the Joshuto sub-process. That's the nature of that wrapper script. It can't know what dir you're currently looking at in Joshuto. And it was never intended to be used that way. The hook-scripts get the full path for that purpose: the hook scripts and wrapper script do not need to know anything of what is going in Joshuto.
Sorry, I have really no clue what you're talking about. Mimetypes in the wrapper script? What is there in the wrapper about mime types??? It just provides some functions to the hook scripts...
Joshuto does not send anything to show_image
at all. show_image
(assuming you use the examples from here) is called only by your hook script. And Joshuto calls your hook scripts. That's it. Change your hook scripts so that they print all arguments to some temporary file and you will see what's going on.
Sorry, maybe I had too much 🍺 today. But I have no idea what you're talking about. What do you want to achieve anyway?
Maybe I should get more 🍻... really to warm today...
i should probably clarify.
* `:shell bash` allows me to do `show_image` manually, but i have to provide the full path to the image instead of it being resolved
if i do
:shell bash
, i can use all the exports from the "jo" script, named "jst" in my case. i have to provide all the arguments manually, but i can useshow_image
andremove_image
from the resulting shell. if i call the functions through joshuto automatically, then onlyremove_image
is called, according to ueberzugpp's logging.* changing mimetypes accepted in the wrapper script has resulted in only "remove" commands being sent to ueberzugpp.
this is where i made a mistake in what i said. if i change this part of on_preview_shown
, i get no obvious change. whether that's removing the *);;
, or changing these mimetypes to image/*
, nothing seems to change in on_preview_shown
's behavior.
case "$mimetype" in
*)
remove_image
;;
image/png)
show_image "$path" $x $y $width $height
;;
image/jpeg)
show_image "$path" $x $y $width $height
;;
esac
it seems like joshuto isn't sending anything to show_image other than the file name. what's going on?
when i do show_image
automatically, through joshuto, i get no preview, and ueberzugpp reports as though show_image
never even happened. i can't find where the arguments to show_image
are coming from, so i can only really guess what's happening with it.
there's some error in the script and i can't figure out how to debug it.
if i call the functions through joshuto automatically, then only...
Not sure what you mean by through joshuto automatically. I assume you're talking about calling them from the hook-scripts, like done in the recipes.
there's some error in the script and i can't figure out how to debug it.
Well, when I was writing the hooks, I ususally just did stuff like
path="$1" # Full path of the previewed file
x="$2" # x coordinate of upper left cell of preview area
y="$3" # y coordinate of upper left cell of preview area
width="$4" # Width of the preview pane (number of fitting characters)
height="$5" # Height of the preview pane (number of fitting characters)
mimetype=$(file --mime-type -Lb "$path")
echo "$path $x $y $width $height ($mimetype)" >> /tmp/noodlesoup
...
So, just write the arguments to some tmp file and then tail -f
it in another terminal. You can add several such debug outputs in different places in the hook script.
And now that I'm looking into your code extract, I think I saw the bug.... 😆
You have your *)
case first. So this will always match and just “remove” an image. The case-branches which call show_image
will never be reached.
Try
case "$mimetype" in
*)
echo "remove!" >> /tmp/noodlesoup
remove_image
;;
image/png)
echo "PNG!" >> /tmp/noodlesoup
show_image "$path" $x $y $width $height
;;
image/jpeg)
echo "JPG!" >> /tmp/noodlesoup
show_image "$path" $x $y $width $height
;;
esac
And I guess you will never see a “PNG!” or a “JPG!” in your /tmp/noodlesoup
....
So, just put your wildcard-case to the bottom:
case "$mimetype" in
image/png)
show_image "$path" $x $y $width $height
;;
image/jpeg)
show_image "$path" $x $y $width $height
;;
*)
remove_image
;;
esac
yes, so the problem still persists when i outright remove the star case, is what i'm saying
interestingly, when i direct output from the script to a log file, it sees the mimetype for a json file, but not for a jpg. it doesn't even echo a path for the selected file when it's a picture. i can confirm the file exists, and it does get output, but it doesn't always
new lines for jst
:
...
export jstlog="$joshuto_wrap_tmp"/jstlog
touch $jstlog
new lines for on_preview_shown
:
...
# Find out mimetype and extension
mimetype=$(file --mime-type -Lb "$path")
extension=$(/bin/echo "${path##*.}" | awk '{print tolower($0)}')
echo $path >> $jstlog
echo $mimetype >> $jstlog
case "$mimetype" in
# *)
# remove_image
# ;;
image/png)
echo $(date +"[%y-%m-%d %I:%M %P]") "png detected" "$path" $x $y $width $height >> $jstlog
show_image "$path" $x $y $width $height
;;
image/jpeg)
echo "$(date +"[%y-%m-%d %I:%M %P")" "jpeg detected" "$path" $x $y $width $height >> $jstlog
show_image "$path" $x $y $width $height
;;
esac
output from $jstlog in my joshuto folder:
/home/dogbold/.config/joshuto/bookmarks.toml
text/plain
/home/dogbold/.config/joshuto/icons.toml
text/plain
/home/dogbold/.config/joshuto/joshuto.toml
text/plain
/home/dogbold/.config/joshuto/keymap.toml
text/plain
/home/dogbold/.config/joshuto/mimetype.toml
text/plain
/home/dogbold/.config/joshuto/on_preview_removed
text/x-shellscript
/home/dogbold/.config/joshuto/on_preview_shown
text/x-shellscript
/home/dogbold/.config/joshuto/preview_file.old.sh
text/x-shellscript
/home/dogbold/.config/joshuto/preview_file.sh
text/x-shellscript
/home/dogbold/.config/joshuto/theme.toml
text/plain
output from $jstlog when in my pictures folder, which has 103 files:
/home/dogbold/pictures/.metadata.json
application/json
/home/dogbold/pictures/.metadata.json
application/json
aha! bug partly fixed. if i add this to preview_file
, i get an actual logging about images:
image/*)
## Preview as text conversion
~/.config/joshuto/on_preview_shown "${FILE_PATH}" && exit 0
exit 1 ;;
resulting logging (interestingly, dimensions are missing):
[23-07-16 01:38 pm] image detected /home/dogbold/pictures/baby_sulphur.png
Dimensions:
/home/dogbold/pictures/background2-tinypc.jpg
image/jpeg
[23-07-16 01:38 pm] image detected /home/dogbold/pictures/background2-tinypc.jpg
Dimensions:
/home/dogbold/pictures/background2-tinypc.png
image/png
[23-07-16 01:38 pm] image detected /home/dogbold/pictures/background2-tinypc.png
Dimensions:
/home/dogbold/pictures/blue-token.png
image/png
[23-07-16 01:38 pm] image detected /home/dogbold/pictures/blue-token.png
Dimensions:
/home/dogbold/pictures/dogbold-icon.png
image/png
[23-07-16 01:38 pm] image detected /home/dogbold/pictures/dogbold-icon.png
Ehh... wait... in your first example, where you have the logging without any image files mentioned, have you actually hovered your cursor over image files?
If yes, that would mean that the hook was not invoked at all. 🤔 What does your text-preview script (preview_file.sh
in the example config) return for image files?
Do you maybe return something ≠ 0
on images there? Is the preview area (3rd panel on the right) at all visible for image files in Joshuto?
(You must return 0
there to show the preview area at all, only then, the “preview_shown” hook will be called...)
that seems to have gotten it working! (i can fix mediainfo being in the wrong spot)
takeaway for anyone reading maybe worth putting into the docs:
preview_file
are not an output, they're a required input to joshuto(i can fix mediainfo being in the wrong spot)
If you don't want any text output, just don't print any from your preview_file.sh
but only terminate with exit 0
.
If you want to have both, text and an image preview, this recipe shows how that can be achieved.
you can (and should) make the joshuto wrapper script output to a log file
Not sure if one should. I don't do that. :wink:
the exit codes from preview_file are not an output, they're a required input to joshuto
They are both. The exit codes and stdout
are the way the preview_file.sh
gives back information to Joshuto.
That's a pretty common way to get information back from a sub-process. It's also documented on top of the example script. However, I would agree that this special relation between the preview_file.sh
and the image preview could be documented more explicit.
oops, accidentally reopened. lol ctrl-enter
Not sure if one should. I don't do that. :wink:
i'll sure keep doing that, because it's handy to have logging like this
i've been trying to hack at this a little bit.
:shell bash
allows me to doshow_image
manually, but i have to provide the full path to the image instead of it being resolvedit seems like joshuto isn't sending anything to show_image other than the file name. what's going on?