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:
1 parent
31f4a4e16f
commit
e9571ab1d7
1 file changed
+4
-13
+4
-13
@@ -11,17 +11,8 @@
|
|||||||
#
|
#
|
||||||
# You may put this in a function called fish_user_key_bindings.
|
# You may put this in a function called fish_user_key_bindings.
|
||||||
|
|
||||||
function lfcd
|
function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)"
|
||||||
set tmp (mktemp)
|
# `command` is needed in case `lfcd` is aliased to `lf`.
|
||||||
# `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.
|
||||||
command lf -last-dir-path=$tmp $argv
|
cd "$(command lf -print-last-dir $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
|
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user