From e9571ab1d7da99aab6cbc400d495f1939e0ebb1f Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Mon, 11 Dec 2023 06:12:30 +0200 Subject: [PATCH] Enable completions and add description for lfcd.fish and simplify the code (#1503) * Enable completions and add description for lfcd.fish A simple addition of `--wraps=lf` to the function definition will enable the standard lf completions to be used for `lfcd` function as well. * Simplify lfcd.fish * lfcd.fish: unquote $argv * lfcd.fish: further simplify * lfcd.fish: cd only on clean exit * lfcd.fish: further simplify and add a coment on quoting semantics * lfcd.fish: amend comment style --- etc/lfcd.fish | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/etc/lfcd.fish b/etc/lfcd.fish index 6a6ada9b..9007021b 100644 --- a/etc/lfcd.fish +++ b/etc/lfcd.fish @@ -11,17 +11,8 @@ # # You may put this in a function called fish_user_key_bindings. -function lfcd - set tmp (mktemp) - # `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 - if test -d "$dir" - if test "$dir" != (pwd) - cd $dir - end - end - end +function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)" + # `command` is needed in case `lfcd` is aliased to `lf`. + # Quotes will cause `cd` to not change directory if `lf` prints nothing to stdout due to an error. + cd "$(command lf -print-last-dir $argv)" end