I think it would be nice to have the parent shell cd to the directory opened in lf on exit, similarly to what [fff] does.
There would be two components to this feature:
(The 'cancel' command would make it possible to quit lf without having the shell cd to the opened directory.)
fff achieves step 1 by writing to a file on disk, but I don't this really is necessary. Instead of to stdout, the user interface can be printed directly to the tty, leaving room in stdout for echoing the directory.
Thoughts?
It's already possible, you can find some scripts (for posix shell or fish) in the repo for doing just that
Aha, thank you. But that solution doesn’t seem to cover step 2?
18 feb. 2019 kl. 23:46 skrev Olivier Perret notifications@github.com:
It's already possible, you can find some scripts (for posix shell or fish) in the repo for doing just that
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
@jocap We have shell commands which pauses the ui and use the underlying stdin/stdout/stderr for input and output so things can get confusing if we use stdout instead of a separate file though I haven't actually tried this. We don't have a separate command implemented for step 2 but maybe someone may have already come up with a clever solution that I haven't considered. My workaround for this case is simply to go back with cd - after exiting if necessary.
I think a solution would be for quit to take an optional return code, and in the wrapper script you would only cd if lf returned 0.
@occivink That could work I guess. We can also add a separate command for this. In the meantime, I also thought about a workaround using marks as follows:
push m-
map Q push '-q
@jocap You can put this in your lfrc file. First command marks the inital directory with - key, and the second command assigns Q key to load - mark first before quitting.
Olivier Perret wrote:
I think a solution would be for
quitto take an optional return code, and in the wrapper script you would onlycdiflfreturned 0.
This is a good idea.
gokcehan wrote:
@jocap You can put this in your
lfrcfile. First command marks the inital directory with-key, and the second command assignsQkey to load-mark first before quitting.
And this is a nice workaround. Thank you!
These solutions are pretty neat.
I added the following to my .zshrc:
I found it useful to name the function the same way as the lf binary and call the binary directly using the full path /usr/bin/lf:
lf () {
tmp="$(mktemp)"
/usr/bin/lf --last-dir-path="$tmp" "$@"
if [ -f "$tmp" ]; then
dir="$(cat "$tmp")"
rm -f "$tmp"
if [ -d "$dir" ]; then
if [ "$dir" != "$(pwd)" ]; then
cd "$dir"
fi
fi
fi
}
Also added this to .config/lfrc in order to use Q to return to the original directory:
push m-
map Q push '-q
Thanks!
@nostdm You can also use command lf instead of /usr/bin/lf so you don't have to hardcode the full path.
Love that this feature is up for discussion. Any chance of it coming in a release?
@Glench The workaround already seems to work so I don't think there is anything else we need to do about this. We should probably close this issue.
So the workaround is this?
push m-
map Q push '-q
and it lets you execute the cd command to the current directory displayed in lf? If so, where is the lfrc file go?
@Glench You also need push m- command so it saves the current directory in - mark on startup. Please see the documentation about where the lfrc file go.
Oh sorry, mispaste. But even with that I don't see the expected behavior of leaving my shell cded to the last directory I was in in lf when I do Q. In fact, it says mark-load: no such mark.
$ cat ~/.config/lf/lfrc
push m-
map Q push '-q
@Glench Just to be clear, if you want to change to the last directory, you need to be using the script provided in /etc/lfcd.sh. If you want to cancel changing directory when using lfcd you can use that mapping. I have tried it again and it is working as intended. If you're still having trouble feel free to leave further information.
@gokcehan I get random promts for mark-save: on startup with that tweak
# For exiting in the original direcotry lf started from
push m-
map Q push '-q
They are appear randomly, most noticably while launching lf right after exiting one in the same shell.
I'm also having issues with the suggested mapping but it isn't related to mark-save:. When I press Q I get mark-load: no such mark even though I can see the - mark saved when just pressing '.
okay, I got something working with the /etc/lfcd.sh script in this repo but it's not what I wanted.
To be clear, what I was hoping for was the normal behavior of the lf program but a keyboard shortcut that does the cd on exit. So I would type lf then go to a different directory. If I type q then it just quits as normal and doesn't change directory but if I type Q (or cd or something) then it quits and changes the current working directory.
Is this possible currently or a planned feature?
@Glench You can play around with the mappings to get what you want. For example:
push m-
map q push '-q
map Q quit
You can also define commands for this purpose.
@freed00m @ranebrown I have been able to reproduce it once but I can't do it again. It seems like a random bug. I'm marking this issue as a bug in the meantime.
Seems like it might be related to using -. Using a character like w seems to work. (I think map q push '-q creates a recursive mapping, didn't work for me at least). Using the below there is a delay when exiting using q for some reason.
push mw
map q push 'w:quit<enter>
map Q push :quit<enter>
@ranebrown I wrote the above example from head head and you're right, there is a recursive mapping, so q should be as in your example. I don't think it is needed for Q though.
Regarding the bug, I still can't produce it using w mark so I'm not sure if it's related.
There was a race condition with push commands which was most likely the reason for this bug and it is fixed in r17 release. Closing this issue now. Feel free to report back if the issue persists.
Delay issues seems to be fixed. Thanks!
Most helpful comment
okay, I got something working with the
/etc/lfcd.shscript in this repo but it's not what I wanted.To be clear, what I was hoping for was the normal behavior of the
lfprogram but a keyboard shortcut that does the cd on exit. So I would typelfthen go to a different directory. If I typeqthen it just quits as normal and doesn't change directory but if I typeQ(orcdor something) then it quits and changes the current working directory.Is this possible currently or a planned feature?