Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify running lf applications #1088

Closed
og900aero opened this issue Jan 20, 2023 · 4 comments
Closed

Identify running lf applications #1088

og900aero opened this issue Jan 20, 2023 · 4 comments

Comments

@og900aero
Copy link

I would like to make it so that every time an lf is opened, a test is run on all lf instances regarding the size of the window, so that if it is smaller than a certain size, it turns off the preview image. I wrote the script, but I ran into a problem about how I can refer to each individual lf instance. I see only two cases in the documentation:
The current instance is: lf -remote "send $id echo hello world"
All instances: lf -remote 'send echo hello world'
Also, if I give the given client the id number after send, I can also run a command on it. But how do I know under what id number all the lf clients are running? How can I list it so that I can pass it to a variable.

@ilyagr
Copy link
Collaborator

ilyagr commented Jan 20, 2023

From memory (you should double-check), I think the id of each process is the same as its process id. So, pgrep should give it to you. I'm not sure what the way to get the ids of all programs launched from some terminal is, but I think it should be possible.

For your usecase, I would just send a command to all instances of lf to check the terminal size and do something if it's small.

@og900aero
Copy link
Author

For your usecase, I would just send a command to all instances of lf to check the terminal size and do something if it's small.

And how can I do it? I tried the following, but it doesn't work (terminal command: tput cols):

lf -remote "send $tput cols"
lf -remote "send shell tput cols"
lf -remote "send shell $(tput cols)"

Either I get an error message, or all lf shows the $ sign in the bottom bar and waits for the command.

@ilyagr
Copy link
Collaborator

ilyagr commented Jan 22, 2023

Firstly, newer versions of tput may simply fail to work for some strange reason. See #718.

Back to your questions, I think that's an issue with quoting which can get really confusing in such examples as they get more complicated.

From my shell, lf -remote 'send $tput cols', lf -remote 'send !tput cols' and lf -remote 'send %tput cols' all work. In the first one, it's important to use single quotes In double-quotes, you'd need to replace $ with \$.

If you do this from lf rather than a shell, you'll need more quoting. Try

cmd qq %{{
  lf -remote 'send !tput cols'
}}

You can replace ! with $.

@og900aero
Copy link
Author

Firstly, newer versions of tput may simply fail to work for some strange reason. See #718.

Back to your questions, I think that's an issue with quoting which can get really confusing in such examples as they get more complicated.

From my shell, lf -remote 'send $tput cols', lf -remote 'send !tput cols' and lf -remote 'send %tput cols' all work. In the first one, it's important to use single quotes In double-quotes, you'd need to replace $ with \$.

If you do this from lf rather than a shell, you'll need more quoting. Try

cmd qq %{{
  lf -remote 'send !tput cols'
}}

You can replace ! with $.

Aha. When I changed double-quotes with single-quotes, then working great, thank u! So now it was easy to solve that every time lf is started, it sends a check to every instance to see if it needs to be resized:

&{{
	lf -remote 'send %if [ $lf_width -le 120 ]; then lf -remote "send $id no_preview"; else lf -remote "send $id yes_preview"; fi'
}}

cmd no_preview :{{
    set nopreview
    set ratios 1
    set info size:time
    map mm yes_preview
    $ctpvclear
}}

cmd yes_preview :{{
    set ratios 1:1
    set preview
    set info size:time
    map mm no_preview
}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants