Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shubham-cpp opened this issue Jan 1, 2024 · 0 comments
Open

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

shubham-cpp opened this issue Jan 1, 2024 · 0 comments

Comments

@shubham-cpp
Copy link

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
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
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant