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
This commit is contained in:
postsolar authored and GitHub committed 2023-12-11 15:12:30 +11:00
1 parent 31f4a4e16f
commit e9571ab1d7
1 file changed
+4 -13
+4 -13
View File
@@ -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