From a4fa5d36c9fd23e0a64423832a945cf9ccf81151 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Sat, 11 Feb 2023 08:55:49 -0800 Subject: [PATCH] Make `lfcd` examples safer for people who alias `lf` to `lfcd` (#1049) People keep running into an infinite loop and being confused. See https://github.com/gokcehan/lf/issues/140#issuecomment-1256368250 and https://github.com/gokcehan/lf/discussions/1043. This fixes the issues in `lfcd.sh` and `lfcd.fish`. For the other scripts, I'm not sure whether this issue exists or is fixable. One of the discussions above also suggested the need to document the key binding better. --- etc/lfcd.fish | 5 +++-- etc/lfcd.sh | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/etc/lfcd.fish b/etc/lfcd.fish index d318df22..6a6ada9b 100644 --- a/etc/lfcd.fish +++ b/etc/lfcd.fish @@ -5,7 +5,7 @@ # mkdir -p ~/.config/fish/functions # ln -s "/path/to/lfcd.fish" ~/.config/fish/functions # -# You may also like to assign a key to this command: +# You may also like to assign a key (Ctrl-O) to this command: # # bind \co 'set old_tty (stty -g); stty sane; lfcd; stty $old_tty; commandline -f repaint' # @@ -13,7 +13,8 @@ function lfcd set tmp (mktemp) - lf -last-dir-path=$tmp $argv + # `command` is needed in case `lfcd` is aliased to `lf` + command lf -last-dir-path=$tmp $argv if test -f "$tmp" set dir (cat $tmp) rm -f $tmp diff --git a/etc/lfcd.sh b/etc/lfcd.sh index 984ba2ca..323e4060 100644 --- a/etc/lfcd.sh +++ b/etc/lfcd.sh @@ -8,7 +8,7 @@ # source "$LFCD" # fi # -# You may also like to assign a key to this command: +# 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 @@ -16,7 +16,8 @@ lfcd () { tmp="$(mktemp)" - lf -last-dir-path="$tmp" "$@" + # `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"