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

command to add to or remove from cut list. #377

Closed
mohkale opened this issue Jun 7, 2020 · 6 comments
Closed

command to add to or remove from cut list. #377

mohkale opened this issue Jun 7, 2020 · 6 comments
Labels

Comments

@mohkale
Copy link

mohkale commented Jun 7, 2020

I'm sure this has been asked before but I couldn't find any mention of it so I'll ask anyways.

at the moment if you try to cut a new file, the previous file selection is completely erased. There doesn't appear to be a way to easily remove a file you've cutted by accident, aside from remarking every file aside from the accidental one and then cutting again.

ranger has the da and dr commands which do this, I'd like lf to have something similair for both cut (:cut-add and :cut-remove) and copy (:copy-add and :copy-remove).

Given how lfs keys are currently bound we probably can't introduce default bindings for them, but I'd like them to be available all the same. This doesn't seem like the kind of thing that should be (or maybe even could be) implemented as an external command.

@gokcehan
Copy link
Owner

gokcehan commented Jun 7, 2020

@mohkale You can read the list of cut files from the server using lf -remote 'load' so I feel like it should be possible to implement these as custom commands.

@mohkale
Copy link
Author

mohkale commented Jun 8, 2020

You can read the list of cut files from the server using lf -remote 'load'

Ok, wow, I totally missed that in the documentation. My bad. 😰.

So just to clarify how I'd go about this. For example for :cut-add I have to:

  1. read the currently cut files using lf -remote load
  2. clear all the selected files (because their already available as $fx and if I don't then I may accidentally unselect them at the next step).
  3. for every file in lf -remote load and $fx I have to select them
  4. and then run cut.

I'm just worried about that 3rd step, is there a way to do it efficiently? The obvious approach would be to first run lf -remote "send $id select \"$file\"" and then lf -remote "send $id toggle" but that would spawn two processes for every file, I'm sure there's a way to combine it into one command for each file... but is there a way to pipe a selection of files to lf and have it select them?

@gokcehan
Copy link
Owner

gokcehan commented Jun 8, 2020

@mohkale Similar to remote load command, we also have a remote save command you can use to change the copy/cut list on the server. You don't need to select the files again in the client to cut them again. There is a small example in the documentation which you can try to adopt to your case.

@mohkale
Copy link
Author

mohkale commented Jun 9, 2020

okay, thnx for your help so far. I've gotten something close to working but lf doesn't seem to update it's display to account for the newly set items.

cmd cut-add ${{
    files=$(lf -remote load | tail -n +2)
    newline=$'\n'

    # change to $fx to add current file when no toggled
    # files exist.
    new_files=$(echo "$files$newline$fs" | sort | uniq)

    lf -remote "save${newline}move${newline}$new_files"
    lf -remote "send $id unselect"
}}

if I:

  • mark 2 files and run :cut to select them
  • mark 2 other files and run :cut-add to add them to the cut list.
  • lf doesn't seem to highlight the 2 other files the same as the first 2 files.

Hitting :reload or :load doesn't seem to help.

If I quit lf and create a new client their colored correctly.

EDIT:

seems to be because :sync isn't called automatically when lf -remote save is called. I've added that to :cut-add and it's working great 😄. I've got something working for :cut-remove as well, but I'll test it out a bit before adding it to the wiki.

@mohkale
Copy link
Author

mohkale commented Jun 9, 2020

and done 😎. Again, thnx for your help.

@mohkale mohkale closed this as completed Jun 9, 2020
@gokcehan
Copy link
Owner

@mohkale No problem, thanks for updating the tips wiki.

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

No branches or pull requests

2 participants