lf icon indicating copy to clipboard operation
lf copied to clipboard

Send multiple remote commands

Open zhengpd opened this issue 2 years ago • 1 comments

Hi everyone,

Is there any way to send multiple remote commands?

Maybe something like lf -remote 'send $id select $1; open. I failed to find any example from the code or issues.


To be more specific, I'm trying to fix a select file and then open issue.

# example 1 - failure
cmd fzf ${{
result="$(fzf)"
if [ ! -z "$result" ]; then
  lf -remote "send $id select '${result}'"
  lf -remote "send $id open"
fi
}}
# example 2 - success
cmd fzf ${{
result="$(fzf)"
if [ ! -z "$result" ]; then
  lf -remote "send $id select '${result}'"
  sleep 1
  lf -remote "send $id open"
fi
}}

The two remote cmds with a sleep 1 works like I expect. I guess the cmds execution order is not guarantee as the same in cmd definition.

zhengpd avatar May 06 '22 20:05 zhengpd

Wrapping multiple commands in :{{ ... }} should work, i.e. lf -remote "send $id :{{ select '${result}'; open; }.

kmarius avatar Jun 16 '22 20:06 kmarius

hmm got the same question. @kmarius 's suggestion doesn't really work..

jackielii avatar Mar 09 '23 21:03 jackielii

ok so this works:

        lf -remote "send $id :set preview!; set ratios 1"

Although my original config was:

        lf -remote "send $id :set preview off; set ratios 1"

But I get error message:

ratios: should consist of at least two numbers when 'preview' is enabled

But it doesn't make sense: I'm sending preview off first, so when it's setting ratios, preview should be off already. I think this might the issue OP is facing?

jackielii avatar Mar 09 '23 21:03 jackielii

@zhengpd You need to use : (this means lf command) to group multiple commands into a single line. This is stated in the documentation:

https://github.com/gokcehan/lf/blob/6ffc4a4c8aef3cf84b04b44515240612865a4e4e/doc.go#L1057-L1059

So you should be able to use something like this:

cmd fzf ${{
    result="$(fzf)"
    if [ -f "$result" ]; then
        lf -remote "send $id :select '$result'; open"
    fi
}}

@jackielii To disable previews you should use set nopreview, not set preview off. As of 41cdd02572a0ef349482e630bfa71202e8065f05 the recommendation is now to use set preview false.


I think there is no issue here and this can be closed.

joelim-work avatar Mar 28 '23 05:03 joelim-work

@joelim-work Thanks. Colon : works. Cannot remember how I miss the doc last year.

zhengpd avatar Mar 28 '23 08:03 zhengpd