Alternate paste workflow (select then move/copy) doesnt work with multiple instances
Closed this issue · 8 comments
I setup up Alternate paste workflow (select then move/copy) from Wiki/tips.
Working great with one lf, but when I use 2 lf, then print error message in second lf instances: paste: no file in copy/cut buffer
I use Debian 12 Stable and lf r32 version.
One thing:
- Open 2 lf. Select any files in one lf, then move to the second lf and paste, and working fine copy/cut
- Open 1 lf, then select any files, then open second lf, and paste -> get error message: paste: no file in copy/cut buffer
I can't reproduce.
In the second instance the files should already be selected upon startup, and pressing P/p should cut
/copy
the file into the buffer before actually pasting.
I can't reproduce.
In the second instance the files should already be selected upon startup, and pressing P/p should
cut
/copy
the file into the buffer before actually pasting.
Now I try create new empty lfrc file the following contains:
set shellopts '-eu'
set ifs "\n"
cmd load-select &{{
# skip if triggered via save-select from itself
if [ "$1" = "$id" ]; then
exit 0
fi
lf -remote "send $id unselect"
if [ -s ~/.local/share/lf/select ]; then
files=$(tr '\n' '\0' < ~/.local/share/lf/select | xargs -0 printf ' %q')
lf -remote "send $id toggle $files"
fi
}}
cmd save-select &{{
printf "%s" "$fs" > ~/.local/share/lf/select
lf -remote "send load-select $id"
}}
cmd alt-paste &{{
if [ -n "$fs" ]; then
lf -remote "send $id :$1; save-select"
fi
lf -remote "send $id paste"
lf -remote "send $id clear"
lf -remote "send $id unselect"
}}
load-select
map <space> :toggle; down; save-select
map u :unselect; save-select
map v :invert; save-select
map P alt-paste cut
map p alt-paste copy
But doesnt work. When I open second lf, the files doesnt toggle automatically. And when I write :load-select manually, then not select the files from file. The select file contains the selected files.
After testing, I found out what the problem is:
if [ "$1" = "$id" ]; then
exit 0
fi
When I commented these lines, then works. Flickering always when toggle files, but working. So there is something wrong with this test. Maybe with Debian 12 stable?
OK I see what the problem is. That block of code exists to prevent the current instance from updating itself, otherwise it will cause a flicker as you described.
But since you added set shellopts '-eu'
, the -u
flag causes the script to exit immediately when starting up a new instance ($1
isn't defined), and as a result the its selection list isn't synchronized properly.
I have changed the wiki example to use the following:
if [ $# -eq 1 ] && [ "$1" = "$id" ]; then
exit 0
fi
Thanks for reporting. BTW for issues like these, it would be a lot easier if you could get a minimal config file from scratch, and then post it along with the issue description.
Thx, working great now :) And I'm sorry that I didn't start with the minimal config right away.
May I have one more request? It's an old Windows trick, but I often use the glob-select command to select multiple files that are somehow the same (for example, all flac files):
map + push :glob-select<space>*
Then press x, and type .flac, and toggle all flac extansion file. But with alternate paste workflow, doesnt work, because not use save-select command to write select file.
For glob-select
, it's slightly more difficult because it takes an argument unlike toggle
/unselect
/invert
. It's still possible if you create a new wrapper command that invokes save-select
at the end:
cmd globsel &{{
lf -remote "send $id :glob-select \"$1\"; save-select"
}}
Keep in mind that lf
doesn't natively support synchronizing selection across all instances, and that all of this is a hack to get it working.
Thx, working like a charm.
Keep in mind that lf doesn't natively support synchronizing selection across all instances, and that all of this is a hack to get it working.
Yes I know, but this alternate paste workflow is a very good result. Better solution, than original select (cut/copy), then paste, I think.