From 3d74fee6af39fcbd416f67edaed15451dea1698d Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Sat, 18 Nov 2023 06:56:11 +0200 Subject: [PATCH 1/7] 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. --- etc/lfcd.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/lfcd.fish b/etc/lfcd.fish index 6a6ada9b..6f205013 100644 --- a/etc/lfcd.fish +++ b/etc/lfcd.fish @@ -11,7 +11,7 @@ # # 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 lf -last-dir-path=$tmp $argv From 7c40601957b577000acf3986fbc205d99f0e0f1d Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Sat, 18 Nov 2023 07:11:39 +0200 Subject: [PATCH 2/7] Simplify lfcd.fish --- etc/lfcd.fish | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/etc/lfcd.fish b/etc/lfcd.fish index 6f205013..de6eb753 100644 --- a/etc/lfcd.fish +++ b/etc/lfcd.fish @@ -12,16 +12,7 @@ # You may put this in a function called fish_user_key_bindings. 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 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 + command lf -print-last-dir "$argv" \ + | read -l dir && test -n "$dir" && cd "$dir" || true end From 7038f6a2a92668531bd2d48fa62597ce34ddfd6a Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Sat, 18 Nov 2023 12:52:31 +0200 Subject: [PATCH 3/7] lfcd.fish: unquote $argv --- etc/lfcd.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/lfcd.fish b/etc/lfcd.fish index de6eb753..0df5b542 100644 --- a/etc/lfcd.fish +++ b/etc/lfcd.fish @@ -13,6 +13,6 @@ function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)" # `command` is needed in case `lfcd` is aliased to `lf` - command lf -print-last-dir "$argv" \ + command lf -print-last-dir $argv \ | read -l dir && test -n "$dir" && cd "$dir" || true end From 7537fb1698683eebf6e438152d3d3901335efa02 Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Sat, 18 Nov 2023 15:04:39 +0200 Subject: [PATCH 4/7] lfcd.fish: further simplify --- etc/lfcd.fish | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/etc/lfcd.fish b/etc/lfcd.fish index 0df5b542..931c0e90 100644 --- a/etc/lfcd.fish +++ b/etc/lfcd.fish @@ -13,6 +13,5 @@ function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)" # `command` is needed in case `lfcd` is aliased to `lf` - command lf -print-last-dir $argv \ - | read -l dir && test -n "$dir" && cd "$dir" || true + cd (command lf -print-last-dir $argv) end From 1864cd058fb8eb78ed016a2517d3d3e1cc46fe92 Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Mon, 20 Nov 2023 03:01:24 +0200 Subject: [PATCH 5/7] lfcd.fish: cd only on clean exit --- etc/lfcd.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/etc/lfcd.fish b/etc/lfcd.fish index 931c0e90..1427f02f 100644 --- a/etc/lfcd.fish +++ b/etc/lfcd.fish @@ -13,5 +13,6 @@ function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)" # `command` is needed in case `lfcd` is aliased to `lf` - cd (command lf -print-last-dir $argv) + set -l outdir (command lf -print-last-dir $argv) + and cd "$outdir" end From 4c19fe87415e482b006f20a63de8369ce7a31bba Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Mon, 4 Dec 2023 23:33:38 +0200 Subject: [PATCH 6/7] lfcd.fish: further simplify and add a coment on quoting semantics --- etc/lfcd.fish | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/etc/lfcd.fish b/etc/lfcd.fish index 1427f02f..aa5da41f 100644 --- a/etc/lfcd.fish +++ b/etc/lfcd.fish @@ -12,7 +12,7 @@ # You may put this in a function called fish_user_key_bindings. function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)" - # `command` is needed in case `lfcd` is aliased to `lf` - set -l outdir (command lf -print-last-dir $argv) - and cd "$outdir" + # `command` is needed in case `lfcd` is aliased to `lf`, + # and quotes will cause `cd` to fail if `lf` prints nothing to stdout due to an error + cd "$(command lf -print-last-dir $argv)" end From bd330f5fbebf2e889006274bd5c7ec910ade8c56 Mon Sep 17 00:00:00 2001 From: postsolar <120750161+postsolar@users.noreply.github.com> Date: Tue, 5 Dec 2023 20:02:16 +0200 Subject: [PATCH 7/7] lfcd.fish: amend comment style --- etc/lfcd.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/lfcd.fish b/etc/lfcd.fish index aa5da41f..9007021b 100644 --- a/etc/lfcd.fish +++ b/etc/lfcd.fish @@ -12,7 +12,7 @@ # You may put this in a function called fish_user_key_bindings. function lfcd --wraps="lf" --description="lf - Terminal file manager (changing directory on exit)" - # `command` is needed in case `lfcd` is aliased to `lf`, - # and quotes will cause `cd` to fail if `lf` prints nothing to stdout due to an error + # `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