From 9b1cc19b6218b1d84ee9810eede776af1ddd81e4 Mon Sep 17 00:00:00 2001 From: shovanrai Date: Fri, 7 Apr 2023 15:17:29 +0545 Subject: [PATCH] lf | added lf --- .config/lf/lfcd.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .config/lf/lfcd.sh diff --git a/.config/lf/lfcd.sh b/.config/lf/lfcd.sh new file mode 100644 index 0000000..323e406 --- /dev/null +++ b/.config/lf/lfcd.sh @@ -0,0 +1,30 @@ +# Change working dir in shell to last dir in lf on exit (adapted from ranger). +# +# You need to either copy the content of this file to your shell rc file +# (e.g. ~/.bashrc) or source this file directly: +# +# LFCD="/path/to/lfcd.sh" +# if [ -f "$LFCD" ]; then +# source "$LFCD" +# fi +# +# You may also like to assign a key (Ctrl-O) to this command: +# +# bind '"\C-o":"lfcd\C-m"' # bash +# bindkey -s '^o' 'lfcd\n' # zsh +# + +lfcd () { + tmp="$(mktemp)" + # `command` is needed in case `lfcd` is aliased to `lf` + command 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 +}