gokcehan / lf

Terminal file manager
MIT License
7.79k stars 331 forks source link

how to use `lf -remote` in cmd? #1787

Closed Jaehaks closed 3 months ago

Jaehaks commented 3 months ago

Thank you for your efforts

I'm windows user and use cmd prompt for shell. I tested simple code to check ls -remote works properly with this code

  cmd z ${{
    lf -remote "send %id% echo test" 
  }}

But it just blinks the lf and doesn't work anything

I tested with powershell version 7.4.4 as wiki said buf After I write set shellflag "-cwa" in lfrc, other functions doesn't work. (all functions open new cmd prompt)

set shellflag "-cwa"
cmd z ${{
    lf -remote "send $env:id echo test"
}}

What I missed?

joelim-work commented 3 months ago

I'm windows user and use cmd prompt for shell. I tested simple code to check ls -remote works properly with this code

  cmd z ${{
    lf -remote "send %id% echo test" 
  }}

But it just blinks the lf and doesn't work anything

You can't use multiline commands (i.e. {{ ... }}) for Windows CMD, see https://github.com/gokcehan/lf/wiki/Troubleshoot#multiline-shell-commands-dont-work-on-windows

If you use only a single line like below, then that should work:

cmd z %lf -remote "send %id% echo test"

I also recommend to use % (shell-pipe) instead of $ (shell), which will write the output to the status line at the bottom, otherwise you won't be able to see the output until you quit lf.


I tested with powershell version 7.4.4 as wiki said buf After I write set shellflag "-cwa" in lfrc, other functions doesn't work. (all functions open new cmd prompt)

set shellflag "-cwa"
cmd z ${{
  lf -remote "send $env:id echo test"
}}

Did you also configure the shell to use PowerShell instead of Windows CMD?

set shell pwsh
Jaehaks commented 3 months ago

@joelim-work

You can't use multiline commands (i.e. {{ ... }}) for Windows CMD, see https://github.com/gokcehan/lf/wiki/Troubleshoot#multiline-shell-commands-dont-work-on-windows

I didn't recognize the Troubleshoot document Thank you for your reply.

set shell pwsh

It misunderstand it is automatic. I'll try it

Jaehaks commented 3 months ago

I add like this to use zoxide integration with cmd and it works, Thanks @joelim-work

I'm using set shell cmd

  1. in lfrc
## -- command - zoxide
cmd z &%LF_CONFIG_HOME%\lf\lf_z.bat
cmd zi $%LF_CONFIG_HOME%\lf\lf_zi.bat
  1. in lf_z.bat
@echo off

setlocal enabledelayedexpansion
chcp 65001 > nul 2>&1
for /F "usebackq tokens=*" %%a in (`zoxide query --exclude "%cd%" %*`) do (
    set z_dir=%%a
    set "z_dir=!z_dir:\=\\!"
    lf -remote "send %id% cd '!z_dir!'"
)
endlocal
  1. in lf_zi.bat
@echo off

setlocal enabledelayedexpansion
chcp 65001 > nul 2>&1
for /F "usebackq tokens=*" %%a in (`zoxide query -i --exclude "%cd%" %*`) do (
    set z_dir=%%a
    set "z_dir=!z_dir:\=\\!"
    lf -remote "send %id% cd '!z_dir!'"
)
endlocal