~exec64/imv#6: 
rename current image

Any idea how to do image renaming?

I tried this:

# Rename image
<Shift+R> = exec imv_rename "$imv_current_file"; close

with the imv_rename script:

#!/bin/sh

pat="\.(jpg|JPG|jpeg|JPEG)$"

old_name="$(readlink -f $1)"
if [ ! -f "$old_name" ] ; then
    exit
fi
dir_name=${old_name%/*}
base_name=${old_name##*/}
new_name=$(wofi -S dmenu -p 'New name: ' 2>/dev/null)

if [[ -z "$new_name" ]] ; then
    exit
fi

if [[ "$new_name" =~ $pat ]] ; then
    mv -v "$old_name" "$dir_name/$new_name"
else
    mv -v "$old_name" "$dir_name/${new_name}.jpg"
fi

but imv somehow cycles in the endless cycle asking for the new name. Any idea what I do wrong?

Status
REPORTED
Submitter
~mcepl
Assigned to
No-one
Submitted
2 years ago
Updated
a month ago
Labels
No labels applied.

~mcepl 2 years ago

OK, the problem is ; close in the end of the keybinding. Without that imv is confused about the name of the file, but otherwise it works well.

Robert Bruner 3 months ago · edit

Had the exact same issue in a simpler setup. In the [binds] section of the config file, I added the following line:

<Shift+R> = exec newname="$(wofi -d)"; echo $newname

I was trying to accomplish the same thing in the long run as the first guy, but this was a testing phase. This script runs without

The script never echoed anything to any terminal, but Wofi kept restarting as soon as anything was entered. The only way out of this was to restart my Hyprland instance.

I'm trying to understand: How does an infinite loop even happen here? There are no loops in my code at all, so where does this loop come from? I've reached the limit of my debugging abilities here.

I post this here to document a sort of "minimum case" that causes the problem. There is some incredibly cursed interaction between the way imv handles exec scripts, and wofi. I hope that someone more familiar with the project can solve this, because I'm stumped.

Robert Bruner 3 months ago · edit

I meant to say that I can run the script after the "exec" fine in terminal, and it produces exactly the results I want. This issue only occurs when trying to run it through the imv keybind.

Robert Bruner 3 months ago · edit

I have reduced the problem down to as simple as running "<Shift+R> = exec wofi -d", which causes the error. Hyprland has a similar feature with keybinding, and running the exact same command through it produces the expected results rather than what imv produces.

This must therefore be due to the way imv handles scripts.

blankie 3 months ago · edit

You probably experienced this bug: https://todo.sr.ht/~exec64/imv/7 This patch should fix it: https://lists.sr.ht/~exec64/imv-devel/patches/39476

Register here or Log in to comment, or comment via email.