thimc / lfimg

Image preview support for lf (list files) using Überzug
GNU General Public License v3.0
252 stars 45 forks source link

lfrun & quit-on-cd(from lf wiki) not working #55

Open shubham-cpp opened 7 months ago

shubham-cpp commented 7 months ago

I was trying to make the lfrun work with quit-on-cd which mentions a trick to cd to the current directory when quitting. But for some reason its not working as expected. If I run regular lf it exits and cds to expected directory but when I do lfrun it doesn't

Minimal ~/.config/lf/lfrc ```lfrc set cleaner ~/.config/lf/cleaner set previewer ~/.config/lf/preview set shell bash set shellopts '-eu' set ifs "\n" cmd quit-and-cd &{{ pwd > $LF_CD_FILE notify-send "quit-and-cd" "$LF_CD_FILE\n$(cat $LF_CD_FILE)" lf -remote "send $id quit" }} map Q quit-and-cd ```
Modified ~/.local/bin/lfrun ```bash #!/bin/bash set -e cleanup() { exec 3>&- command rm "$FIFO_UEBERZUG" } lf() { # https://github.com/gokcehan/lf/wiki/Tips#cd-to-current-directory-on-quit export LF_CD_FILE=/var/tmp/.lfcd-$$ command lf $@ if [ -s "$LF_CD_FILE" ]; then local DIR="$(realpath "$(cat "$LF_CD_FILE")")" if [ "$DIR" != "$PWD" ]; then echo "cd to $DIR" cd "$DIR" fi command rm "$LF_CD_FILE" fi unset LF_CD_FILE } if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then lf "$@" else [ ! -d "$HOME/.cache/lf" ] && mkdir --parents "$HOME/.cache/lf" export FIFO_UEBERZUG="$HOME/.cache/lf/ueberzug-$$" mkfifo "$FIFO_UEBERZUG" ueberzug layer -s -p json <"$FIFO_UEBERZUG" & exec 3>"$FIFO_UEBERZUG" # trap cleanup HUP INT QUIT TERM PWR EXIT # Also tried this one trap cleanup HUP INT QUIT TERM PWR EXIT lf "$@" 3>&- fi ```