For example, the feh
program can delete the currently viewed image, presumably using the rm
command at some point. Let's say that instead of deleting the file, we want to run a trash script, say trash.sh
. Is there anyway of running feh
but tricking it into running trash.sh
every time it calls rm
?
1 Answer
You need to modify the sources of feh
and run an arbitrary script instead of unlink()
system call in C
language, then compile new code:
git clone https://github.com/derf/feh.git
cd feh
cat<<EOF > trashbin.patch
--- src/filelist.c 2023-09-18 23:19:53.444892742 +0200
+++ src/filelist_new.c 2023-09-18 23:19:11.293556737 +0200
@@ -112,7 +112,11 @@
gib_list *feh_file_rm_and_free(gib_list * list, gib_list * l)
{
- unlink(FEH_FILE(l->data)->filename);
+ //unlink(FEH_FILE(l->data)->filename);
+ char command[255];
+ sprintf(command, "/usr/local/bin/trashbin.sh %s", FEH_FILE(l->data)->filename);
+ system(command);
+
return(feh_file_remove_from_list(list, l));
}
EOF
patch src/filelist.c < trashbin.patch
make
sudo make install
Then, create:
/usr/local/bin/trashbin.sh
with what you want, like
#!/bin/sh
mkdir -p ~/.local/trashbin
/bin/mv -- "$@" ~/.local/trashbin
feh
, would be running the systemrm
command.Ctrl
+Delete
action? As terdon says, it's unlikely that it calls the externalrm
command for removing images.unlink(2)
system call. It is possible to intercept this using function interposition, but that's almost never the correct answer (and it may not be 100% effective, and may have lots of edge cases around properly dealing with temporary files, etc).