Giter Club home page Giter Club logo

Comments (10)

gokcehan avatar gokcehan commented on July 17, 2024 6

@ivegotasthma Ok so I have checked ranger now. You can use the same mapping as ranger. For that you need to unbind d key first. Then add dd for cutting and dD for deletion. Following should work (not tested):

map d # leave the command name empty like this for unmapping
map dd delete
map dD $IFS=':'; rm -rf $fx

If you don't want to set IFS variable for each such command as above, you can use the ifs options to set it for all automatically. Ranger prompts for deleting multiple files. You can achieve something like that by prompting in your custom shell command (again not tested):

map dD ${{
    echo 'delete?[y/n]'
    read ans
    [ $ans = 'y' ] && echo 'deleting files..' || echo 'cancelled.'
}}

You need to replace echo commands with rm accordingly. You can also customize this to not prompt when there is only one file selected. Lastly you can create a named command for this and then map dD to insert the command name to wait for your enter key using the push command (again not tested):

cmd remove ${{
    echo 'delete?[y/n]'
    read ans
    [ $ans = 'y' ] && echo 'deleting files..' || echo 'cancelled.'
}}
map dD push :remove

Basically, I think everything in ranger should also be possible in lf. See the doc and the example configuration file for more examples. If there is anything missing we can improve them.

from lf.

gokcehan avatar gokcehan commented on July 17, 2024

@ivegotasthma delete command is actually just cutting and it is named after the corresponding vi command and keybinding. By default there are no actual file deletion command is provided. You can use something like $rm $f interactively or just bind this or maybe $rm -rf $fx to a key yourself. Alternatively you can use the trash command from lfrc.example and/or bind it to a key.

What is that custom mapping you mention?

from lf.

 avatar commented on July 17, 2024

Thanks for clearing up the issue, works great. The mapping I mentioned is: map D $rm -fr "$fx". Is it possible to run a command on the marked for cutting files?

from lf.

gokcehan avatar gokcehan commented on July 17, 2024

@ivegotasthma File names are separated with : so your mapping will not work properly when you have quotes around $fx (see doc for more detail).

Can you rephrase what you mean by running a command on the marked for cutting files?

from lf.

 avatar commented on July 17, 2024

@gokcehan Thanks for the correction. I notice that with that mapping: map D $rm -fr $fx I cannot delete a selection of files, marked with the purple flair.

By the files marked for cutting I mean the files that are marked for deletion, with the red indicator before them. I'd like to be able to run a command only on that selection because I find it a bit dangerous to arbitrary delete a file, I'd like to have a small moment of consideration before it. Which selection it for deletion does.

It's the same in ranger, you press the d key for delete but it opens a menu for a variety of options where are related to the destruction of the file, one of which is the movement of the file, eg. cutting it or purging.

PS. is it possible to remove files selected for deletion with the red flair?

from lf.

 avatar commented on July 17, 2024

@gokcehan I applogize for misartuculating this:
PS. is it possible to remove files selected for deletion with the red flair?.
I meat to ask if it's possible to unselect files marked for deletion with the red flair or select files that are in a certain selection, so that I could mark files with red and then delete them, ei, having specific flairs for different actions. Red would be dangerous operations for example. It's possible to unselect files marked with purple but not with red.

Here's the command that I ended up with:

# purge the unclean
cmd remove ${{
    if [ -z $fs ]; then
        rm -fr $f
    else
        IFS=':'; echo $fs | tr " " "\n"
        echo 'delete? [y/n]'
        read ans

        [ $ans = 'y' ] && (echo 'deleting files...' && rm -fr $fs) || (echo 'cancelled...')
    fi
}}
map d
map dd delete
map dD push :remove

from lf.

gokcehan avatar gokcehan commented on July 17, 2024

@ivegotasthma Ahh sorry, now I understand what you mean, at least some of it.

Currently we're missing a command to clear the selection (red/yellow) but you can workaround for this by directly communicating with your socket using netcat if it support unix sockets (e.g. OpenBSD netcat), something along the line:

map c ${{
    echo "save move" | nc -U /tmp/lf.${USER}.sock
    echo "send sync" | nc -U /tmp/lf.${USER}.sock
}}

First line will save an empty list of files for moving (i.e. red) so it will clear previous selected files. Second line will sync file lists of clients with the server. Note that remote commands and protocol used for communication here are still experimental and undocumented so it will likely break in the future as changes are made. One thing we might add is a command line flag to send arbitrary strings to the socket using lf so nc will not be required (e.g. lf -send "save move").

Other than that, you seem to have some extra ideas about color codes for file lists. Some of these might be achieved using echo "load" | nc -U /tmp/lf.${USER}.sock which will return the current file list saved in the server. But there is still only one file list held in the server (i.e. red or yellow). I haven't experimented much with these yet, not sure what things are possible.

from lf.

dumblob avatar dumblob commented on July 17, 2024

I second the proposal of @ivegotasthma with regards to unselecting all selections. The idea lf -send "save move" of @gokcehan seems to be the safest one, so I'm supporting it (in contrast with reliance on pure socket communication which is fragile due to possible changes in lf).

@ivegotasthma could you please rename this topic to something like "Unselect red selections"?

from lf.

gokcehan avatar gokcehan commented on July 17, 2024

@dumblob Just to be clear, lf -send "save move" is also about using socket communication but using lf instead of an external command, so it may still break if we change the communication protocol. The good thing is we don't have to pass the socket name so it won't break if we change the socket name at some point.

By the way, I tried to implement a native clear command for this purpose the other day but there was a race somewhere so I didn't push it. I suspect there is still something wrong with the asynchronous event loop. I will take a look at it when I find some time.

from lf.

gokcehan avatar gokcehan commented on July 17, 2024

I have now added a native clear command (default c) and also a -remote command line flag. Closing this issue now.

from lf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.